|
1 | 1 | package com.thealgorithms.sorts;
|
2 | 2 |
|
| 3 | +import com.thealgorithms.sorts.TopologicalSort.Graph; |
| 4 | +import java.util.LinkedList; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
3 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
4 | 8 | import static org.junit.jupiter.api.Assertions.assertIterableEquals;
|
5 | 9 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
6 | 10 |
|
7 |
| -import com.thealgorithms.sorts.TopologicalSort.Graph; |
8 |
| -import java.util.LinkedList; |
9 |
| -import org.junit.jupiter.api.Test; |
10 | 11 |
|
11 | 12 | class TopologicalSortTest {
|
12 | 13 |
|
@@ -59,4 +60,18 @@ public void failureTest() {
|
59 | 60 | + "Back edge: 6 -> 2";
|
60 | 61 | assertEquals(exception.getMessage(), expected);
|
61 | 62 | }
|
| 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 | + } |
62 | 77 | }
|
0 commit comments