diff options
author | Haidong Ji | 2020-05-20 18:37:36 -0500 |
---|---|---|
committer | Haidong Ji | 2020-05-20 18:37:36 -0500 |
commit | a3d28d9ea91f90af072066b2a77030e929ab0f0e (patch) | |
tree | be4ae5b824f003f1050590415043f685ad13f564 /src/test | |
parent | 2dd66619bbd1bf45e092c54f70d89d8f27d269dc (diff) |
Check if DAG (Directed Acyclic Graph) done. In the exercise it's Checking Consistency of CS Curriculum. For the clock variable to assign pre-visit and post-visit values, I used a trick of defining the clock as int[1], so its mutable and I can increment it. I don't know if that's a best practice, but for now I'm happy that the program is good. Fun stuff!
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/AcyclicityTest.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/test/AcyclicityTest.java b/src/test/AcyclicityTest.java new file mode 100644 index 0000000..9d67894 --- /dev/null +++ b/src/test/AcyclicityTest.java @@ -0,0 +1,55 @@ +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.*; + +class AcyclicityTest { + + @Test + void test() { + ArrayList<ArrayList<Integer>> adj = new ArrayList<>(); + for (int i = 0; i < 4; i++) { + adj.add(new ArrayList<>()); + } + + adj.get(0).add(1); + adj.get(3).add(0); + adj.get(1).add(2); + adj.get(2).add(0); + + assertEquals(1, Acyclicity.acyclic(adj)); + } + + @Test + void test1() { + ArrayList<ArrayList<Integer>> adj = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + adj.add(new ArrayList<>()); + } + + adj.get(0).add(1); + adj.get(1).add(2); + adj.get(0).add(2); + adj.get(2).add(3); + adj.get(0).add(3); + adj.get(1).add(4); + adj.get(2).add(4); + + assertEquals(0, Acyclicity.acyclic(adj)); + } + + @Test + void test2() { + ArrayList<ArrayList<Integer>> adj = new ArrayList<>(); + for (int i = 0; i < 4; i++) { + adj.add(new ArrayList<>()); + } + + adj.get(0).add(1); + adj.get(2).add(1); + adj.get(3).add(2); + + assertEquals(0, Acyclicity.acyclic(adj)); + } +}
\ No newline at end of file |