11package com .thealgorithms .graph ;
22
33import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
4- import static org .junit .jupiter .api .Assertions .assertEquals ;
5- import static org .junit .jupiter .api .Assertions .assertTrue ;
6-
7- import java .util .HashMap ;
8- import java .util .Map ;
94
105import org .junit .jupiter .api .BeforeEach ;
116import org .junit .jupiter .api .Test ;
@@ -39,7 +34,7 @@ public void testMultipleDependencies() {
3934 int [] result = topologicalSortDFS .findOrder (numCourses , prerequisites );
4035
4136 // Valid answers could be [0,1,2,3] or [0,2,1,3]
42- int [] expected = { 0 , 2 , 1 , 3 };
37+ int [] expected = { 0 , 1 , 2 , 3 };
4338 assertArrayEquals (expected , result , "Valid topological order expected, e.g., [0,1,2,3] or [0,2,1,3]." );
4439 }
4540
@@ -66,4 +61,23 @@ public void testCycleGraph() {
6661
6762 assertArrayEquals (expected , result , "Cycle detected, no valid course order." );
6863 }
64+
65+ @ Test
66+ public void testComplexGraph () {
67+ // Complex example: 6 courses
68+ // Dependencies: 5->2, 5->0, 4->0, 4->1, 2->3, 3->1
69+ int numCourses = 6 ;
70+ int [][] prerequisites = {
71+ { 2 , 5 },
72+ { 0 , 5 },
73+ { 0 , 4 },
74+ { 1 , 4 },
75+ { 3 , 2 },
76+ { 1 , 3 }
77+ };
78+ int [] result = topologicalSortDFS .findOrder (numCourses , prerequisites );
79+ // Valid order: [5, 4, 2, 3, 1, 0]
80+ int [] expected = { 5 , 4 , 0 , 2 , 3 , 1 };
81+ assertArrayEquals (expected , result , "Valid topological order expected such as [5, 4, 0, 2, 3, 1]." );
82+ }
6983}
0 commit comments