-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathstronglyConnectedComp_test.go
75 lines (69 loc) · 1.44 KB
/
stronglyConnectedComp_test.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package graph
import (
"testing"
)
func sccSetupGraph() graph {
g := newGraph()
g.AddVertex("a")
g.AddVertex("b")
g.AddVertex("c")
g.AddVertex("d")
g.AddVertex("e")
g.AddVertex("f")
g.AddVertex("g")
g.AddVertex("h")
g.AddEdge(edge{"a", "b"})
g.AddEdge(edge{"b", "e"})
g.AddEdge(edge{"e", "a"})
g.AddEdge(edge{"e", "f"})
g.AddEdge(edge{"b", "f"})
g.AddEdge(edge{"b", "c"})
g.AddEdge(edge{"c", "d"})
g.AddEdge(edge{"d", "c"})
g.AddEdge(edge{"c", "g"})
g.AddEdge(edge{"f", "g"})
g.AddEdge(edge{"g", "f"})
g.AddEdge(edge{"g", "h"})
g.AddEdge(edge{"d", "h"})
g.AddEdge(edge{"h", "h"})
return g
}
func sccGolden() (scc graph) {
scc = newGraph()
bea := newGraph()
bea.AddVertex("a")
bea.AddVertex("e")
bea.AddVertex("b")
bea.AddEdge(edge{"a", "b"})
bea.AddEdge(edge{"b", "e"})
bea.AddEdge(edge{"e", "a"})
scc.AddVertex(bea)
cd := newGraph()
cd.AddVertex("c")
cd.AddVertex("d")
cd.AddEdge(edge{"c", "d"})
cd.AddEdge(edge{"d", "c"})
scc.AddVertex(cd)
gf := newGraph()
gf.AddVertex("f")
gf.AddVertex("g")
gf.AddEdge(edge{"f", "g"})
gf.AddEdge(edge{"g", "f"})
scc.AddVertex(gf)
h := newGraph()
h.AddVertex("h")
h.AddEdge(edge{"h", "h"})
scc.AddVertex(h)
scc.AddEdge(edge{bea, cd})
scc.AddEdge(edge{bea, gf})
scc.AddEdge(edge{cd, gf})
scc.AddEdge(edge{cd, h})
scc.AddEdge(edge{gf, h})
return
}
func TestSCC(t *testing.T) {
g := sccSetupGraph()
scc := scc(g)
expScc := sccGolden()
checkGraphInOrder(t, scc, expScc)
}