-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmap_test.go
74 lines (62 loc) · 1.4 KB
/
bitmap_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
package imagine
import (
"testing"
"github.com/stretchr/testify/assert"
)
type BitMapLenTest struct {
Val interface{}
ExpectLen int
}
func TestBitMapLen(t *testing.T) {
ts := []BitMapLenTest{
{Val: NewBitMap(20).data, ExpectLen: 3},
{Val: NewBitMap(100).data, ExpectLen: 13},
{Val: NewBitMap(200).data, ExpectLen: 25},
{Val: NewBitMap(612).data, ExpectLen: 77},
{Val: NewBitMap(1995).data, ExpectLen: 250},
}
for _, bmt := range ts {
assert.Len(t, bmt.Val, bmt.ExpectLen)
}
}
type BitMapFuncTest struct {
F func(b *BitMap)
ExpectFunc func(b *BitMap)
}
func TestBitMapGetSetGrow(t *testing.T) {
b := NewBitMap(20)
bs := []BitMapFuncTest{
{F: func(b *BitMap) {
b.Set(10)
b.Set(18)
}, ExpectFunc: func(b *BitMap) {
assert.Equal(t, true, b.Get(10))
assert.Equal(t, true, b.Get(18))
assert.Equal(t, false, b.Get(12))
assert.Equal(t, false, b.Get(1))
assert.Equal(t, false, b.Get(20))
}},
{
F: func(b *BitMap) {
b.Set(12)
b.UnSet(18)
}, ExpectFunc: func(b *BitMap) {
assert.Equal(t, true, b.Get(12))
assert.Equal(t, false, b.Get(18))
assert.Equal(t, false, b.Get(1))
},
}, {
F: func(b *BitMap) {
b.Grow(10)
}, ExpectFunc: func(b *BitMap) {
assert.Equal(t, false, b.Get(25))
assert.Equal(t, false, b.Get(30))
assert.Len(t, b.data, 4)
},
},
}
for _, bt := range bs {
bt.F(b)
bt.ExpectFunc(b)
}
}