From 660b75d0d541295b445c266bebe1149e5cf8cdc9 Mon Sep 17 00:00:00 2001 From: FelixAnthonisen Date: Tue, 12 Nov 2024 20:05:38 +0100 Subject: [PATCH] add more tests --- .../felix/astParsing/TestTypeHandler.java | 2 +- .../felix/graph/TestClassHierarchyGraph.java | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/test/java/anthonisen/felix/astParsing/TestTypeHandler.java b/src/test/java/anthonisen/felix/astParsing/TestTypeHandler.java index f331034..4ff7df7 100644 --- a/src/test/java/anthonisen/felix/astParsing/TestTypeHandler.java +++ b/src/test/java/anthonisen/felix/astParsing/TestTypeHandler.java @@ -8,7 +8,7 @@ import java.util.Map; import com.github.javaparser.ast.type.ClassOrInterfaceType; -import anthonisen.felix.astParsing.util.TypeHandler; +import io.github.bldl.astParsing.util.TypeHandler; public class TestTypeHandler { @Test diff --git a/src/test/java/anthonisen/felix/graph/TestClassHierarchyGraph.java b/src/test/java/anthonisen/felix/graph/TestClassHierarchyGraph.java index 2c25c99..14da203 100644 --- a/src/test/java/anthonisen/felix/graph/TestClassHierarchyGraph.java +++ b/src/test/java/anthonisen/felix/graph/TestClassHierarchyGraph.java @@ -2,16 +2,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashSet; import java.util.Set; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test;; +import org.junit.jupiter.api.Test; + +import io.github.bldl.graph.ClassHierarchyGraph;; public class TestClassHierarchyGraph { - IDirectedGraph graph; + ClassHierarchyGraph graph; @BeforeEach public void setUpGraph() { @@ -48,6 +51,14 @@ public void testAddEdge() { assertTrue(found); } + @Test + public void testCantAddEdgeThatCreatesCycle() { + for (int i = 0; i < 5; ++i) { + graph.addEdge(i, i + 1); + } + assertThrows(IllegalArgumentException.class, () -> graph.addEdge(4, 0)); + } + @Test public void testCantAddEdge() { assertFalse(graph.addEdge(2, 10)); @@ -61,4 +72,13 @@ public void testGetVertices() { graph.getVertices().forEach(vertex -> actualVerts.add(vertex)); assertEquals(expectedVerts, actualVerts); } + + @Test + public void testIsDescendant() { + for (int i = 0; i < 4; ++i) { + graph.addEdge(i, i + 1); + } + assertTrue(graph.isDescendant(0, 4)); + assertFalse(graph.isDescendant(4, 0)); + } }