@@ -16,10 +16,7 @@ class TopologicalSortTest {
1616 @ Test
1717 @ DisplayName ("Simple DAG returns correct ordering" )
1818 void simpleDAG () {
19- List <int []> edges = Arrays .asList (
20- new int [] { 0 , 1 },
21- new int [] { 0 , 2 },
22- new int [] { 1 , 3 },
19+ List <int []> edges = Arrays .asList (new int [] { 0 , 1 }, new int [] { 0 , 2 }, new int [] { 1 , 3 },
2320 new int [] { 2 , 3 });
2421 int [] result = TopologicalSort .sort (4 , edges );
2522 assertArrayEquals (new int [] { 0 , 1 , 2 , 3 }, result );
@@ -38,10 +35,7 @@ void emptyGraph() {
3835 @ Test
3936 @ DisplayName ("Graph with cycle returns null" )
4037 void graphWithCycle () {
41- List <int []> edges = Arrays .asList (
42- new int [] { 0 , 1 },
43- new int [] { 1 , 2 },
44- new int [] { 2 , 0 });
38+ List <int []> edges = Arrays .asList (new int [] { 0 , 1 }, new int [] { 1 , 2 }, new int [] { 2 , 0 });
4539 assertNull (TopologicalSort .sort (3 , edges ));
4640 }
4741
@@ -50,8 +44,7 @@ void graphWithCycle() {
5044 void coursePrerequisites () {
5145 // Example: Course prerequisites where edge [a,b] means course a must be taken
5246 // before b
53- List <int []> edges = Arrays .asList (
54- new int [] { 1 , 0 }, // Calculus I -> Calculus II
47+ List <int []> edges = Arrays .asList (new int [] { 1 , 0 }, // Calculus I -> Calculus II
5548 new int [] { 2 , 0 }, // Linear Algebra -> Calculus II
5649 new int [] { 1 , 3 }, // Calculus I -> Differential Equations
5750 new int [] { 2 , 3 } // Linear Algebra -> Differential Equations
@@ -69,8 +62,7 @@ void coursePrerequisites() {
6962 @ Test
7063 @ DisplayName ("Invalid vertex throws exception" )
7164 void invalidVertex () {
72- List <int []> edges = Arrays .asList (
73- new int [] { 0 , 5 } // Vertex 5 is invalid for a graph with 3 vertices
65+ List <int []> edges = Arrays .asList (new int [] { 0 , 5 } // Vertex 5 is invalid for a graph with 3 vertices
7466 );
7567 assertThrows (IllegalArgumentException .class , () -> TopologicalSort .sort (3 , edges ));
7668 }
@@ -84,11 +76,7 @@ void nullEdgeList() {
8476 @ Test
8577 @ DisplayName ("sortAndDetectCycle throws exception for cyclic graph" )
8678 void detectCycleThrowsException () {
87- List <int []> edges = Arrays .asList (
88- new int [] { 0 , 1 },
89- new int [] { 1 , 2 },
90- new int [] { 2 , 0 });
91- assertThrows (IllegalArgumentException .class ,
92- () -> TopologicalSort .sortAndDetectCycle (3 , edges ));
79+ List <int []> edges = Arrays .asList (new int [] { 0 , 1 }, new int [] { 1 , 2 }, new int [] { 2 , 0 });
80+ assertThrows (IllegalArgumentException .class , () -> TopologicalSort .sortAndDetectCycle (3 , edges ));
9381 }
94- }
82+ }
0 commit comments