diff --git a/src/test/java/com/thealgorithms/sorts/TopologicalSortTest.java b/src/test/java/com/thealgorithms/sorts/TopologicalSortTest.java index de115b458fe7..d5588b2b968e 100644 --- a/src/test/java/com/thealgorithms/sorts/TopologicalSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/TopologicalSortTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertIterableEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.thealgorithms.sorts.TopologicalSort.Graph; import java.util.LinkedList; @@ -59,4 +60,18 @@ public void failureTest() { + "Back edge: 6 -> 2"; assertEquals(exception.getMessage(), expected); } + @Test + void testEmptyGraph() { + Graph graph = new Graph(); + LinkedList sorted = TopologicalSort.sort(graph); + assertTrue(sorted.isEmpty()); + } + @Test + void testSingleNode() { + Graph graph = new Graph(); + graph.addEdge("A", ""); + LinkedList sorted = TopologicalSort.sort(graph); + assertEquals(1, sorted.size()); + assertEquals("A", sorted.getFirst()); + } }