forked from RoaringBitmap/roaring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitmapcontainer_test.go
67 lines (53 loc) · 1.5 KB
/
bitmapcontainer_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
package roaring
import (
. "github.com/smartystreets/goconvey/convey"
"math/rand"
"testing"
)
func TestBitmapContainerNumberOfRuns024(t *testing.T) {
Convey("bitmapContainer's numberOfRuns() function should be correct against the runContainer equivalent",
t, func() {
seed := int64(42)
p("seed is %v", seed)
rand.Seed(seed)
trials := []trial{
{n: 1000, percentFill: .1, ntrial: 10},
/*
trial{n: 100, percentFill: .5, ntrial: 10},
trial{n: 100, percentFill: .01, ntrial: 10},
trial{n: 100, percentFill: .99, ntrial: 10},
*/
}
tester := func(tr trial) {
for j := 0; j < tr.ntrial; j++ {
p("TestBitmapContainerNumberOfRuns023 on check# j=%v", j)
ma := make(map[int]bool)
n := tr.n
a := []uint16{}
draw := int(float64(n) * tr.percentFill)
for i := 0; i < draw; i++ {
r0 := rand.Intn(n)
a = append(a, uint16(r0))
ma[r0] = true
}
showArray16(a, "a")
// RunContainer compute this automatically
rc := newRunContainer16FromVals(false, a...)
rcNr := rc.numberOfRuns()
p("rcNr from run container is %v", rcNr)
// vs bitmapContainer
bc := newBitmapContainer()
for k := range ma {
bc.iadd(uint16(k))
}
bcNr := bc.numberOfRuns()
So(bcNr, ShouldEqual, rcNr)
//fmt.Printf("\nnum runs was: %v\n", rcNr)
}
p("done with randomized bitmapContianer.numberOrRuns() checks for trial %#v", tr)
}
for i := range trials {
tester(trials[i])
}
})
}