-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypeVarSet_test.go
68 lines (60 loc) · 2.3 KB
/
typeVarSet_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
package hm
import "testing"
var tvSetTests = []struct {
op string
tvs0 TypeVarSet
tvs1 TypeVarSet
expected TypeVarSet
ind int
eq bool
}{
{"set", TypeVarSet{'a', 'a', 'a'}, nil, TypeVarSet{'a'}, 0, false},
{"set", TypeVarSet{'c', 'b', 'a'}, nil, TypeVarSet{'a', 'b', 'c'}, 0, false},
{"intersect", TypeVarSet{'a', 'b', 'c'}, TypeVarSet{'d', 'e', 'f'}, TypeVarSet{}, -1, false},
{"intersect", TypeVarSet{'a', 'b', 'c'}, TypeVarSet{'b', 'c', 'd'}, TypeVarSet{'b', 'c'}, -1, false},
{"intersect", TypeVarSet{'a', 'b', 'c'}, nil, nil, -1, false},
{"intersect", TypeVarSet{'a', 'b', 'c'}, TypeVarSet{'c', 'b', 'a'}, TypeVarSet{'a', 'b', 'c'}, 0, true},
{"union", TypeVarSet{'a', 'b'}, TypeVarSet{'c', 'd'}, TypeVarSet{'a', 'b', 'c', 'd'}, 0, false},
{"union", TypeVarSet{'a', 'c', 'b'}, TypeVarSet{'c', 'd'}, TypeVarSet{'a', 'b', 'c', 'd'}, 0, false},
{"union", TypeVarSet{'a', 'b'}, nil, TypeVarSet{'a', 'b'}, 0, false},
{"diff", TypeVarSet{'a', 'b', 'c'}, TypeVarSet{'d', 'e', 'c'}, TypeVarSet{'a', 'b'}, 0, false},
{"diff", TypeVarSet{'a', 'b', 'c'}, TypeVarSet{'c', 'd', 'e'}, TypeVarSet{'a', 'b'}, 0, false},
{"diff", TypeVarSet{'a', 'b', 'c'}, TypeVarSet{'d', 'e', 'f'}, TypeVarSet{'a', 'b', 'c'}, 0, false},
}
func TestTypeVarSet(t *testing.T) {
for i, tst := range tvSetTests {
var s TypeVarSet
switch tst.op {
case "set":
s = tst.tvs0.Set()
if !s.Equals(tst.expected) {
t.Errorf("%s op (%d): expected: %v, got %v", tst.op, i, tst.expected, s)
}
case "intersect":
s = tst.tvs0.Intersect(tst.tvs1)
if !s.Equals(tst.expected) {
t.Errorf("%s op (%d): expected: %v, got %v", tst.op, i, tst.expected, s)
}
case "union":
s = tst.tvs0.Union(tst.tvs1)
if !s.Equals(tst.expected) {
t.Errorf("%s op (%d): expected: %v, got %v", tst.op, i, tst.expected, s)
}
case "diff":
s = tst.tvs0.Difference(tst.tvs1)
if !s.Equals(tst.expected) {
t.Errorf("%s op (%d): expected: %v, got %v", tst.op, i, tst.expected, s)
}
}
if ind := s.Index('a'); ind != tst.ind {
t.Errorf("%s op %d index : expected %d got %v", tst.op, i, tst.ind, ind)
}
if eq := tst.tvs0.Equals(tst.tvs1); eq != tst.eq {
t.Errorf("%s op %d eq: expected %t got %v", tst.op, i, tst.eq, eq)
}
}
tvs := TypeVarSet{'a'}
if !tvs.Equals(tvs) {
t.Error("A set should be equal to itself")
}
}