-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitarray_test.go
More file actions
60 lines (45 loc) · 782 Bytes
/
Copy pathbitarray_test.go
File metadata and controls
60 lines (45 loc) · 782 Bytes
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
package disttopk
import "testing"
import "math/rand"
func TestBitArray(t *testing.T) {
n := 10000
a := NewBitArray(uint(n))
set := make(map[uint]bool)
for i := 0; i < n/10; i++ {
j := rand.Int() % n
set[uint(j)] = true
a.Set(uint(j))
}
for i := 0; i < n; i++ {
j := uint(i)
expected := false
_, ok := set[j]
if ok {
expected = true
}
actual := a.Check(j)
if expected != actual {
t.Fail()
}
}
}
func TestBitArraySerialize(t *testing.T) {
n := 10000
a := NewBitArray(uint(n))
for i := 0; i < n/10; i++ {
j := rand.Int() % n
a.Set(uint(j))
}
b, err := SerializeObject(a)
if err != nil {
panic(err)
}
var obj BitArray
err = DeserializeObject(&obj, b)
if err != nil {
panic(err)
}
if !a.Equal(&obj) {
t.Fail()
}
}