22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
44import static org .junit .jupiter .api .Assertions .assertFalse ;
5+ import static org .junit .jupiter .api .Assertions .assertThrows ;
56import static org .junit .jupiter .api .Assertions .assertTrue ;
67
78import java .util .HashSet ;
89import java .util .Set ;
910
1011import org .junit .jupiter .api .BeforeEach ;
11- import org .junit .jupiter .api .Test ;;
12+ import org .junit .jupiter .api .Test ;
13+
14+ import io .github .bldl .graph .ClassHierarchyGraph ;;
1215
1316public class TestClassHierarchyGraph {
14- IDirectedGraph <Integer > graph ;
17+ ClassHierarchyGraph <Integer > graph ;
1518
1619 @ BeforeEach
1720 public void setUpGraph () {
@@ -48,6 +51,14 @@ public void testAddEdge() {
4851 assertTrue (found );
4952 }
5053
54+ @ Test
55+ public void testCantAddEdgeThatCreatesCycle () {
56+ for (int i = 0 ; i < 5 ; ++i ) {
57+ graph .addEdge (i , i + 1 );
58+ }
59+ assertThrows (IllegalArgumentException .class , () -> graph .addEdge (4 , 0 ));
60+ }
61+
5162 @ Test
5263 public void testCantAddEdge () {
5364 assertFalse (graph .addEdge (2 , 10 ));
@@ -61,4 +72,13 @@ public void testGetVertices() {
6172 graph .getVertices ().forEach (vertex -> actualVerts .add (vertex ));
6273 assertEquals (expectedVerts , actualVerts );
6374 }
75+
76+ @ Test
77+ public void testIsDescendant () {
78+ for (int i = 0 ; i < 4 ; ++i ) {
79+ graph .addEdge (i , i + 1 );
80+ }
81+ assertTrue (graph .isDescendant (0 , 4 ));
82+ assertFalse (graph .isDescendant (4 , 0 ));
83+ }
6484}
0 commit comments