diff options
author | Haidong Ji | 2020-05-16 21:22:14 -0500 |
---|---|---|
committer | Haidong Ji | 2020-05-16 21:22:14 -0500 |
commit | 2dd66619bbd1bf45e092c54f70d89d8f27d269dc (patch) | |
tree | 78d9eef9e53f9389b299012e3b92eb0f2625012e /src/test | |
parent | bc5a6815181068e76316aa4a611647124d18ba48 (diff) |
ConnectedComponents (Adding Exits to Maze) done. I didn't build my test cases properly initially: when v and w are connected, they should be in each other's ArrayList. Once that's fixed, it was easy.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/ConnectedComponentsTest.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/ConnectedComponentsTest.java b/src/test/ConnectedComponentsTest.java new file mode 100644 index 0000000..2e0888c --- /dev/null +++ b/src/test/ConnectedComponentsTest.java @@ -0,0 +1,39 @@ +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.*; + +class ConnectedComponentsTest { + + @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(2).add(1); + adj.get(3).add(2); + adj.get(0).add(3); + + assertEquals(1, ConnectedComponents.numberOfComponents(adj)); + } + + @Test + void test1() { + ArrayList<ArrayList<Integer>> adj = new ArrayList<>(); + for (int i = 0; i < 4; i++) { + adj.add(new ArrayList<>()); + } + + adj.get(0).add(1); + adj.get(1).add(0); + adj.get(2).add(1); + adj.get(1).add(2); + + assertEquals(2, ConnectedComponents.numberOfComponents(adj)); + } + +}
\ No newline at end of file |