-
Notifications
You must be signed in to change notification settings - Fork 0
/
TarjanAlgorithmSCCTest.java
46 lines (35 loc) · 1.34 KB
/
TarjanAlgorithmSCCTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.ttahb.graph;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
public class TarjanAlgorithmSCCTest {
@Test
public void testTarjanAlgorithm(){
TarjanAlgorithmSCC tarjanAlgorithmSCC = new TarjanAlgorithmSCC(8);
tarjanAlgorithmSCC.addDirectedEdge(0,1);
tarjanAlgorithmSCC.addDirectedEdge(1,2);
tarjanAlgorithmSCC.addDirectedEdge(2,0);
tarjanAlgorithmSCC.addDirectedEdge(3,4);
tarjanAlgorithmSCC.addDirectedEdge(3,7);
tarjanAlgorithmSCC.addDirectedEdge(4,5);
tarjanAlgorithmSCC.addDirectedEdge(5,6);
tarjanAlgorithmSCC.addDirectedEdge(5,0);
tarjanAlgorithmSCC.addDirectedEdge(6,4);
tarjanAlgorithmSCC.addDirectedEdge(6,0);
tarjanAlgorithmSCC.addDirectedEdge(6,2);
tarjanAlgorithmSCC.addDirectedEdge(7,3);
tarjanAlgorithmSCC.addDirectedEdge(7,5);
Map<Integer, List<Integer>> output = tarjanAlgorithmSCC.findSCC();
//print sccs
/*for(List<Integer> scc: output.values()){
System.out.println("scc "+scc);
}*/
/*scc [2, 1, 0]
scc [6, 5, 4]
scc [7, 3]*/
// assert 3 strongly connected components.
assertEquals(3,output.size());
}
}