-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathsubgraph_test.go
52 lines (44 loc) · 1.43 KB
/
subgraph_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
package build
import "testing"
func TestSubgraph(t *testing.T) {
cost := func(v, w int) int64 { return int64(10*v + w) }
res := Kn(6).Subgraph(Range(3, 6))
exp := "3 [{0 1} {0 2} {1 2}]"
if mess, diff := diff(res.String(), exp); diff {
t.Errorf("Subgraph %s", mess)
}
Consistent("Subgraph1", t, res)
res = Kn(2).Subgraph(Range(-1, 10))
exp = "2 [{0 1}]"
if mess, diff := diff(res.String(), exp); diff {
t.Errorf("Subgraph %s", mess)
}
Consistent("Subgraph2", t, res)
res = Kn(6).AddCostFunc(cost).Subgraph(Range(3, 6))
exp = "3 [(0 1):34 (0 2):35 (1 0):43 (1 2):45 (2 0):53 (2 1):54]"
if mess, diff := diff(res.String(), exp); diff {
t.Errorf("Subgraph %s", mess)
}
Consistent("Subgraph3", t, res)
res = Kn(6).AddCostFunc(cost).Subgraph(Vertex(1).Or(Vertex(3)))
exp = "2 [(0 1):13 (1 0):31]"
if mess, diff := diff(res.String(), exp); diff {
t.Errorf("Subgraph %s", mess)
}
Consistent("Subgraph4", t, res)
res = Grid(3, 3).Subgraph(Range(0, 4).Or(Range(5, 9)))
exp = "8 [{0 1} {0 3} {1 2} {2 4} {3 5} {4 7} {5 6} {6 7}]"
if mess, diff := diff(res.String(), exp); diff {
t.Errorf("Subgraph %s", mess)
}
Consistent("Subgraph5", t, res)
for m := 0; m < 6; m++ {
for n := 0; n < 6; n++ {
set := Range(1, m).Or(Range(2, n)).Or(Range(3, m+n))
res = Kn(m + n).AddCostFunc(cost).Subgraph(set)
Consistent("Subgraph", t, res)
res = Grid(m, n).AddCostFunc(cost).Subgraph(set)
Consistent("Subgraph", t, res)
}
}
}