Skip to content

Commit 649d814

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

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.thealgorithms.sorts;
22

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;
37
import static org.junit.jupiter.api.Assertions.assertEquals;
48
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
59
import static org.junit.jupiter.api.Assertions.assertThrows;
610

7-
import com.thealgorithms.sorts.TopologicalSort.Graph;
8-
import java.util.LinkedList;
9-
import org.junit.jupiter.api.Test;
1011

1112
class TopologicalSortTest {
1213

@@ -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)