forked from RoaringBitmap/roaring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiter_test.go
More file actions
121 lines (100 loc) · 1.96 KB
/
iter_test.go
File metadata and controls
121 lines (100 loc) · 1.96 KB
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
package roaring
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBackwardCount(t *testing.T) {
array := []int{2, 63, 64, 65, 4095, 4096, 4097, 4159, 4160, 4161, 5000, 20000, 66666}
for _, testSize := range array {
b := New()
for i := uint32(0); i < uint32(testSize); i++ {
b.Add(i)
}
it := Values(b)
count := 0
it(func(_ uint32) bool {
count++
return true
})
assert.Equal(t, testSize, count)
}
}
func TestBackward(t *testing.T) {
t.Run("#1", func(t *testing.T) {
values := []uint32{0, 2, 15, 16, 31, 32, 33, 9999, MaxUint16}
b := New()
for n := 0; n < len(values); n++ {
b.Add(values[n])
}
it := Backward(b)
n := len(values) - 1
it(func(val uint32) bool {
assert.EqualValues(t, val, values[n])
n--
return true
})
it = Backward(b)
n = len(values) - 1
it(func(val uint32) bool {
assert.EqualValues(t, val, values[n])
assert.True(t, n >= 0)
n--
return true
})
})
t.Run("#2", func(t *testing.T) {
b := New()
it := Backward(b)
count := 0
it(func(_ uint32) bool {
count++
return true
})
assert.Equal(t, 0, count)
})
t.Run("#3", func(t *testing.T) {
b := New()
b.AddInt(0)
it := Backward(b)
// only one value zero
it(func(val uint32) bool {
assert.EqualValues(t, 0, val)
return true
})
})
t.Run("#4", func(t *testing.T) {
b := New()
b.AddInt(9999)
it := Backward(b)
// only one value 9999
it(func(val uint32) bool {
assert.EqualValues(t, 9999, val)
return true
})
})
t.Run("#5", func(t *testing.T) {
b := New()
b.AddInt(MaxUint16)
it := Values(b)
// only one value MaxUint16
it(func(val uint32) bool {
assert.EqualValues(t, MaxUint16, val)
return true
})
})
}
func TestValues(t *testing.T) {
b := New()
testSize := 5000
for i := 0; i < testSize; i++ {
b.AddInt(i)
}
it := Values(b)
n := 0
it(func(val uint32) bool {
assert.Equal(t, uint32(n), val)
n++
return true
})
assert.Equal(t, testSize, n)
}