-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvarset_test.go
87 lines (81 loc) · 2.45 KB
/
varset_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
76
77
78
79
80
81
82
83
84
85
86
87
package tnt
import (
"reflect"
"testing"
)
func TestVariableSet(t *testing.T) {
t.Parallel()
type testCase struct {
v1, v2 VariableSet
union, complement VariableSet
intersection, symmetric VariableSet
}
for i, test := range []testCase{
{
v1: NewVariableSetString("a"),
v2: NewVariableSetString(),
union: NewVariableSetString("a"),
complement: NewVariableSetString("a"),
intersection: NewVariableSetString(),
symmetric: NewVariableSetString("a"),
},
{
v1: NewVariableSetString(),
v2: NewVariableSetString("a"),
union: NewVariableSetString("a"),
complement: NewVariableSetString(),
intersection: NewVariableSetString(),
symmetric: NewVariableSetString("a"),
},
{
v1: NewVariableSetString("a"),
v2: NewVariableSetString("a"),
union: NewVariableSetString("a"),
complement: NewVariableSetString(),
intersection: NewVariableSetString("a"),
symmetric: NewVariableSetString(),
},
{
v1: NewVariableSetString("a"),
v2: NewVariableSetString("b"),
union: NewVariableSetString("a", "b"),
complement: NewVariableSetString("a"),
intersection: NewVariableSetString(),
symmetric: NewVariableSetString("a", "b"),
},
{
v1: NewVariableSetString("a", "b"),
v2: NewVariableSetString("b", "c"),
union: NewVariableSetString("a", "b", "c"),
complement: NewVariableSetString("a"),
intersection: NewVariableSetString("b"),
symmetric: NewVariableSetString("a", "c"),
},
} {
check := func(
f func(VariableSet, VariableSet) VariableSet,
fname string,
exp VariableSet,
invert bool,
) {
a, b := test.v1, test.v2
if invert {
a, b = b, a
}
got := f(a, b)
if !reflect.DeepEqual(got, exp) {
t.Errorf("%d: %v %s %v; expected %v, got %v",
i, a, fname, b, exp, got)
}
}
check(VariableSet.Union, "union", test.union, false)
check(VariableSet.Union, "union", test.union, true)
check(VariableSet.Complement, "complement", test.complement, false)
check(VariableSet.Intersection, "intersection", test.intersection, false)
check(VariableSet.Intersection, "intersection", test.intersection, true)
check(VariableSet.SymmetricDifference, "symmetric difference",
test.symmetric, false)
check(VariableSet.SymmetricDifference, "symmetric difference",
test.symmetric, true)
}
}