-
Notifications
You must be signed in to change notification settings - Fork 20
/
match_set_test.go
75 lines (61 loc) · 1.52 KB
/
match_set_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
package quamina
import "testing"
func TestAddX(t *testing.T) {
set := newMatchSet()
// empty exes
set = set.addX()
if !isSameMatches(set) {
t.Errorf("Expected matches to be empty: %+v", set.matches())
}
newSet := set.addX(1)
// existing set should be empty.
if len(set.matches()) > 0 {
t.Errorf("Expected matches to be empty: %+v", set.matches())
}
if !isSameMatches(newSet, 1) {
t.Errorf("Expected matches to be [1]: %+v", set.matches())
}
// add another two values
newSet = newSet.addX(2)
newSet = newSet.addX(3)
if !isSameMatches(newSet, 1, 2, 3) {
t.Errorf("Expected matches to be [1, 2, 3]: %+v", set.matches())
}
}
func TestAddXSingleThreaded(t *testing.T) {
set := newMatchSet()
// empty exes
set.addXSingleThreaded()
if !isSameMatches(set) {
t.Errorf("Expected matches to be empty: %+v", set.matches())
}
set.addXSingleThreaded(1)
// existing set should be empty.
if !isSameMatches(set, 1) {
t.Errorf("Expected matches to be [1]: %+v", set.matches())
}
// add another two values
set.addXSingleThreaded(2)
set.addXSingleThreaded(3)
if !isSameMatches(set, 1, 2, 3) {
t.Errorf("Expected matches to be [1, 2, 3]: %+v", set.matches())
}
}
func (m *matchSet) contains(x X) bool {
_, ok := m.set[x]
return ok
}
func isSameMatches(matchSet *matchSet, exes ...X) bool {
if len(exes) == 0 && len(matchSet.matches()) == 0 {
return true
}
if len(exes) != len(matchSet.matches()) {
return false
}
for _, x := range exes {
if !matchSet.contains(x) {
return false
}
}
return true
}