-
Notifications
You must be signed in to change notification settings - Fork 25
/
simstore6_test.go
80 lines (60 loc) · 1.27 KB
/
simstore6_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
75
76
77
78
79
80
package simstore
import (
"math/rand"
"testing"
)
const size = 1000000
const queries = 1000000
func TestAdd3(t *testing.T) {
s := New3(size, NewU64Slice)
testAdd(t, s, size, queries, 3)
}
func TestAdd3Small(t *testing.T) {
s := New3Small(size)
testAdd(t, s, size, queries, 3)
}
func TestAdd6(t *testing.T) {
s := New6(size, NewU64Slice)
testAdd(t, s, size, queries, 6)
}
func TestAdd3Z(t *testing.T) {
s := New3(size, NewZStore)
testAdd(t, s, size, queries/100, 3)
}
func TestAdd6Z(t *testing.T) {
s := New6(size, NewZStore)
testAdd(t, s, size, queries/100, 6)
}
func testAdd(t *testing.T, s Storage, size, queries, d int) {
rand.Seed(0)
for i := 0; i < size; i++ {
s.Add(uint64(rand.Int63()), uint64(i))
}
sig := uint64(0x001122334455667788)
s.Add(sig, 0xdeadbeef)
s.Finish()
var fails int
for j := 0; j < queries; j++ {
q := sig
// bits := rand.Intn(7)
bits := d
for i := 0; i < bits; i++ {
q ^= 1 << uint(rand.Intn(64))
}
found := s.Find(q)
var foundbeef bool
for _, v := range found {
if v == 0xdeadbeef {
foundbeef = true
break
}
}
if !foundbeef {
t.Errorf("sig = %016x (%064b) (found=%v)\n", sig, sig^q, found)
fails++
}
}
if fails != 0 {
t.Logf("fails = %f", 100*float64(fails)/float64(queries))
}
}