-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbitmap_test.go
43 lines (39 loc) · 854 Bytes
/
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
package bitmap_test
import (
"math/rand"
"testing"
"github.com./andy2046/bitmap"
)
func TestBitmap(t *testing.T) {
t.Logf("MaxBitmapSize -> %d\n", bitmap.MaxBitmapSize)
size := uint64(rand.Int63n(int64(bitmap.MaxBitmapSize)) + 1)
bm := bitmap.New(size)
s := bm.Size()
if s != size {
t.Fatalf("wrong size %d", s)
}
r := bm.SetBit(1, true)
if !r || !bm.GetBit(1) {
t.Fatalf("wrong value at bit %d", 1)
}
r = bm.SetBit(size, true)
if !r || !bm.GetBit(size) {
t.Fatalf("wrong value at bit %d", size)
}
r = bm.SetBit(bitmap.MaxBitmapSize+1, true)
if r || bm.GetBit(bitmap.MaxBitmapSize+1) {
t.Fatal("wrong value")
}
}
func BenchmarkBitmap(b *testing.B) {
x := uint64(10000)
bm := bitmap.New(x)
var index uint64
for i := 0; i < b.N; i++ {
index++
if index == x {
index = 0
}
bm.SetBit(index, !bm.GetBit(index))
}
}