Debian Codegraph @

build/join_test.go

raw symbols SCIP
1 package build
2
3 import "testing"
4
5 func TestJoin(t *testing.T) {
6 cost := func(v, w int) int64 { return int64(10*v + w) }
7 b := EdgeSet{
8 From: Range(0, 4),
9 To: Range(0, 4),
10 Keep: func(v, w int) bool { return true },
11 Cost: Cost(8),
12 }
13 g := Grid(2, 2)
14 res := g.Join(Empty(0), b)
15 exp := "4 [{0 1} {0 2} {1 3} {2 3}]"
16 if mess, diff := diff(res.String(), exp); diff {
17 t.Errorf("Join %s", mess)
18 }
19 Consistent("Join", t, res)
20
21 res = Empty(0).Join(g, b)
22 exp = "4 [{0 1} {0 2} {1 3} {2 3}]"
23 if mess, diff := diff(res.String(), exp); diff {
24 t.Errorf("Join %s", mess)
25 }
26 Consistent("Join", t, res)
27
28 b = EdgeSet{
29 From: Vertex(1),
30 To: Vertex(3),
31 Keep: func(v, w int) bool { return v < w },
32 Cost: Cost(8),
33 }
34 g = Grid(1, 2).AddCostFunc(cost)
35 res = g.Join(g, b)
36 exp = "4 [(0 1):1 (1 0):10 (1 3):8 (2 3):1 (3 2):10]"
37 if mess, diff := diff(res.String(), exp); diff {
38 t.Errorf("Join %s", mess)
39 }
40 Consistent("Join", t, res)
41
42 res = Empty(0).Join(Empty(0), AllEdges())
43 exp = Empty(0).String()
44 if mess, diff := diff(res.String(), exp); diff {
45 t.Errorf("Join %s", mess)
46 }
47 Consistent("Join", t, res)
48
49 res = Empty(2).Join(Empty(3), AllEdges())
50 exp = Kmn(2, 3).String()
51 if mess, diff := diff(res.String(), exp); diff {
52 t.Errorf("Join %s", mess)
53 }
54 Consistent("Join", t, res)
55
56 directed := EdgeSet{
57 Keep: func(v, w int) bool { return v < w },
58 }
59 res = Empty(2).Join(Empty(3), directed)
60 exp = Kmn(2, 3).Keep(func(v, w int) bool { return v < w }).String()
61 if mess, diff := diff(res.String(), exp); diff {
62 t.Errorf("Join %s", mess)
63 }
64 Consistent("Join", t, res)
65
66 directed.Cost = Cost(3)
67 res = Kn(2).AddCost(1).Join(Kn(2).AddCost(2), directed)
68 exp = "4 [{0 1}:1 (0 2):3 (0 3):3 (1 2):3 (1 3):3 {2 3}:2]"
69 if mess, diff := diff(res.String(), exp); diff {
70 t.Errorf("Join %s", mess)
71 }
72 Consistent("Join", t, res)
73
74 full := AllEdges()
75 full.Cost = Cost(3)
76 res = Kn(1).AddCost(1).Join(Kn(1).AddCost(2), full)
77 exp = "2 [{0 1}:3]"
78 if mess, diff := diff(res.String(), exp); diff {
79 t.Errorf("Join %s", mess)
80 }
81 Consistent("Join", t, res)
82
83 directed.Cost = Cost(9)
84 g = Kn(1).AddCost(8).Join(Grid(1, 2).AddCostFunc(cost), directed)
85 exp = "3 [(0 1):9 (0 2):9 (1 2):1 (2 1):10]"
86 if mess, diff := diff(g.String(), exp); diff {
87 t.Errorf("Join %s", mess)
88 }
89 Consistent("Join", t, g)
90
91 res = Empty(2).Join(Empty(3), EdgeSet{Range(0, 1), Range(3, 4), nil, nil})
92 exp = "5 [{0 3}]"
93 if mess, diff := diff(res.String(), exp); diff {
94 t.Errorf("Join %s", mess)
95 }
96 Consistent("Join", t, res)
97
98 b = EdgeSet{Range(0, 1), Range(2, 3), nil, nil}
99 res = Kn(2).AddCost(1).Join(Kn(2).AddCost(2), b)
100 exp = "4 [{0 1}:1 {0 2} {2 3}:2]"
101 if mess, diff := diff(res.String(), exp); diff {
102 t.Errorf("Join %s", mess)
103 }
104 Consistent("Join", t, res)
105
106 for m := 0; m < 4; m++ {
107 for n := 0; n < 4; n++ {
108 b := EdgeSet{Range(m, n), Range(m-n, m+n), nil, nil}
109 res = Kn(m).AddCostFunc(cost).Join(Grid(m, m+n).AddCostFunc(cost), b)
110 Consistent("Join", t, res)
111 res = Grid(m, m+n).AddCostFunc(cost).Join(Kn(m).AddCostFunc(cost), b)
112 Consistent("Join", t, res)
113 }
114 }
115 }