-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathin_test.go
134 lines (110 loc) · 2.27 KB
/
in_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package xim
import (
"fmt"
"reflect"
"testing"
)
func assertBit(t *testing.T, title string, actual, expected Bit) {
t.Helper()
if actual != expected {
t.Errorf("%s: unexpected, actual: `%v`, expected: `%v`", title, actual, expected)
}
}
func TestInBuilderBit(t *testing.T) {
inBuilder := NewInBuilder()
expected := []Bit{
1,
2,
4,
8,
16,
32,
64,
128,
256,
}
for i := range expected {
i := i // escape: Using the variable on range scope `i` in loop literal
t.Run(fmt.Sprintf("%d", expected[i]), func(tr *testing.T) {
assertBit(t, tr.Name(), inBuilder.NewBit(), expected[i])
})
}
uintSize := 16
for i := 9; i < uintSize-1; i++ {
assertBit(t, t.Name(), inBuilder.NewBit(), Bit(1<<uint(i)))
}
assertBit(t, t.Name(), inBuilder.NewBit(), 1<<(uint(uintSize)-1))
// overflow
func() {
defer func() {
if rec := recover(); rec == nil {
t.Errorf("panic expected")
}
}()
inBuilder.NewBit()
}()
}
func TestInBuilderIndexes(t *testing.T) {
inBuilder := NewInBuilder()
a := inBuilder.NewBit()
b := inBuilder.NewBit()
c := inBuilder.NewBit()
d := inBuilder.NewBit()
idxs := inBuilder.Indexes()
if len(idxs) != 0 {
t.Errorf("%s: unexpected, actual: `%v`, expected: `%v`", t.Name(), len(idxs), 0)
}
idxs = inBuilder.Indexes(a, c)
expected := []string{
"1",
"3",
"4",
"5",
"6",
"7",
"9",
"b",
"c",
"d",
"e",
"f",
}
if !reflect.DeepEqual(idxs, expected) {
t.Errorf("%s: unexpected, actual: `%v`, expected: `%v`", t.Name(), idxs, expected)
}
idxs = inBuilder.Indexes(b, d)
expected = []string{
"2",
"3",
"6",
"7",
"8",
"9",
"a",
"b",
"c",
"d",
"e",
"f",
}
if !reflect.DeepEqual(idxs, expected) {
t.Errorf("%s: unexpected, actual: `%v`, expected: `%v`", t.Name(), idxs, expected)
}
}
func TestInBuilderFilters(t *testing.T) {
inBuilder := NewInBuilder()
a := inBuilder.NewBit()
b := inBuilder.NewBit()
c := inBuilder.NewBit()
d := inBuilder.NewBit()
filter := inBuilder.Filter(a, c)
expected := "5"
if filter != expected {
t.Errorf("%s: unexpected, actual: `%v`, expected: `%v`", t.Name(), filter, expected)
}
filter = inBuilder.Filter(b, d)
expected = "a"
if filter != expected {
t.Errorf("%s: unexpected, actual: `%v`, expected: `%v`", t.Name(), filter, expected)
}
}