Debian Codegraph @

build/subgraph_test.go

raw symbols SCIP
1 package build
2
3 import "testing"
4
5 func TestSubgraph(t *testing.T) {
6 cost := func(v, w int) int64 { return int64(10*v + w) }
7
8 res := Kn(6).Subgraph(Range(3, 6))
9 exp := "3 [{0 1} {0 2} {1 2}]"
10 if mess, diff := diff(res.String(), exp); diff {
11 t.Errorf("Subgraph %s", mess)
12 }
13 Consistent("Subgraph1", t, res)
14
15 res = Kn(2).Subgraph(Range(-1, 10))
16 exp = "2 [{0 1}]"
17 if mess, diff := diff(res.String(), exp); diff {
18 t.Errorf("Subgraph %s", mess)
19 }
20 Consistent("Subgraph2", t, res)
21
22 res = Kn(6).AddCostFunc(cost).Subgraph(Range(3, 6))
23 exp = "3 [(0 1):34 (0 2):35 (1 0):43 (1 2):45 (2 0):53 (2 1):54]"
24 if mess, diff := diff(res.String(), exp); diff {
25 t.Errorf("Subgraph %s", mess)
26 }
27 Consistent("Subgraph3", t, res)
28
29 res = Kn(6).AddCostFunc(cost).Subgraph(Vertex(1).Or(Vertex(3)))
30 exp = "2 [(0 1):13 (1 0):31]"
31 if mess, diff := diff(res.String(), exp); diff {
32 t.Errorf("Subgraph %s", mess)
33 }
34 Consistent("Subgraph4", t, res)
35
36 res = Grid(3, 3).Subgraph(Range(0, 4).Or(Range(5, 9)))
37 exp = "8 [{0 1} {0 3} {1 2} {2 4} {3 5} {4 7} {5 6} {6 7}]"
38 if mess, diff := diff(res.String(), exp); diff {
39 t.Errorf("Subgraph %s", mess)
40 }
41 Consistent("Subgraph5", t, res)
42
43 for m := 0; m < 6; m++ {
44 for n := 0; n < 6; n++ {
45 set := Range(1, m).Or(Range(2, n)).Or(Range(3, m+n))
46 res = Kn(m + n).AddCostFunc(cost).Subgraph(set)
47 Consistent("Subgraph", t, res)
48 res = Grid(m, n).AddCostFunc(cost).Subgraph(set)
49 Consistent("Subgraph", t, res)
50 }
51 }
52 }