Skip to content

Commit 8b3c5e4

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

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

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

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

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
5-
import static org.junit.jupiter.api.Assertions.assertThrows;
6-
73
import com.thealgorithms.sorts.TopologicalSort.Graph;
84
import java.util.LinkedList;
95
import org.junit.jupiter.api.Test;
106

7+
import static org.junit.jupiter.api.Assertions.*;
8+
119
class TopologicalSortTest {
1210

1311
@Test
@@ -59,4 +57,18 @@ public void failureTest() {
5957
+ "Back edge: 6 -> 2";
6058
assertEquals(exception.getMessage(), expected);
6159
}
60+
@Test
61+
void testEmptyGraph() {
62+
Graph graph = new Graph();
63+
LinkedList<String> sorted = TopologicalSort.sort(graph);
64+
assertTrue(sorted.isEmpty());
65+
}
66+
@Test
67+
void testSingleNode() {
68+
Graph graph = new Graph();
69+
graph.addEdge("A", "");
70+
LinkedList<String> sorted = TopologicalSort.sort(graph);
71+
assertEquals(1, sorted.size());
72+
assertEquals("A", sorted.getFirst());
73+
}
6274
}

0 commit comments

Comments
 (0)