Skip to content

Commit e79ab50

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

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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+
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;
10+
import static org.junit.jupiter.api.Assertions.assertTrue;
611

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

1113
class TopologicalSortTest {
1214

@@ -59,4 +61,18 @@ public void failureTest() {
5961
+ "Back edge: 6 -> 2";
6062
assertEquals(exception.getMessage(), expected);
6163
}
64+
@Test
65+
void testEmptyGraph() {
66+
Graph graph = new Graph();
67+
LinkedList<String> sorted = TopologicalSort.sort(graph);
68+
assertTrue(sorted.isEmpty());
69+
}
70+
@Test
71+
void testSingleNode() {
72+
Graph graph = new Graph();
73+
graph.addEdge("A", "");
74+
LinkedList<String> sorted = TopologicalSort.sort(graph);
75+
assertEquals(1, sorted.size());
76+
assertEquals("A", sorted.getFirst());
77+
}
6278
}

0 commit comments

Comments
 (0)