Skip to content

Commit 2c80f84

Browse files
committed
Removed graphsearch folder and added additional unit tests for TopologicalSort
1 parent 771d5be commit 2c80f84

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/test/java/com/thealgorithms/sorts/TopologicalSortTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
55
import static org.junit.jupiter.api.Assertions.assertThrows;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
67

78
import com.thealgorithms.sorts.TopologicalSort.Graph;
89
import java.util.LinkedList;
@@ -59,4 +60,18 @@ public void failureTest() {
5960
+ "Back edge: 6 -> 2";
6061
assertEquals(exception.getMessage(), expected);
6162
}
63+
@Test
64+
void testEmptyGraph() {
65+
Graph graph = new Graph();
66+
LinkedList<String> sorted = TopologicalSort.sort(graph);
67+
assertTrue(sorted.isEmpty());
68+
}
69+
@Test
70+
void testSingleNode() {
71+
Graph graph = new Graph();
72+
graph.addEdge("A", "");
73+
LinkedList<String> sorted = TopologicalSort.sort(graph);
74+
assertEquals(1, sorted.size());
75+
assertEquals("A", sorted.getFirst());
76+
}
6277
}

0 commit comments

Comments
 (0)