Debian Codegraph @

build/match_test.go

raw symbols SCIP
1 package build
2
3 import "testing"
4
5 func TestMatch(t *testing.T) {
6 g := Grid(2, 2)
7 b := EdgeSet{
8 Cost: func(v, w int) int64 { return int64(10*v + w) },
9 }
10 res := g.Match(Empty(2), b)
11 exp := "6 [{0 1} {0 2} (0 4):4 {1 3} (1 5):15 {2 3} (4 0):40 (5 1):51]"
12 if mess, diff := diff(res.String(), exp); diff {
13 t.Errorf("Match %s", mess)
14 }
15 Consistent("Match1", t, res)
16
17 c5 := Cycle(5)
18 p5 := Cycle(5).Complement()
19 Petersen := c5.Match(p5, AllEdges())
20 exp = "10 [{0 1} {0 4} {0 5} {1 2} {1 6} {2 3} {2 7} {3 4} {3 8} {4 9} {5 7} {5 8} {6 8} {6 9} {7 9}]"
21 if mess, diff := diff(Petersen.String(), exp); diff {
22 t.Errorf("Match %s", mess)
23 }
24 Consistent("Match2", t, res)
25
26 b = EdgeSet{
27 From: Vertex(1),
28 To: Vertex(3),
29 Keep: func(v, w int) bool { return v < w },
30 Cost: Cost(8),
31 }
32 cost := func(v, w int) int64 { return int64(10*v + w) }
33 g = Grid(1, 2).AddCostFunc(cost)
34 res = g.Match(g, b)
35 exp = "4 [(0 1):1 (1 0):10 (1 3):8 (2 3):1 (3 2):10]"
36 if mess, diff := diff(res.String(), exp); diff {
37 t.Errorf("Match %s", mess)
38 }
39 Consistent("Match3", t, res)
40
41 b = EdgeSet{
42 From: Range(1, 3).Or(Range(4, 6)),
43 To: Range(5, 7).Or(Range(9, 11)),
44 Keep: func(v, w int) bool { return v < w },
45 Cost: cost,
46 }
47 g = Empty(6)
48 res = g.Match(g, b)
49 exp = "12 [(1 6):16 (2 9):29 (4 10):50]"
50 if mess, diff := diff(res.String(), exp); diff {
51 t.Errorf("Match %s", mess)
52 }
53 Consistent("Match4", t, res)
54
55 for m := 0; m < 5; m++ {
56 for n := 0; n < 5; n++ {
57 b := EdgeSet{Range(1, m), Range(m-n, m+n), nil, nil}
58 res = Kn(m).AddCostFunc(cost).Match(Grid(m, m+n).AddCostFunc(cost), b)
59 Consistent("Match", t, res)
60 res = Grid(1, m).AddCostFunc(cost).Match(Kn(m).AddCostFunc(cost), b)
61 Consistent("Match", t, res)
62 }
63 }
64 }