forked from bits-and-blooms/bloom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
murmur_test.go
64 lines (59 loc) · 1.54 KB
/
murmur_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
package bloom
import (
"math/rand"
"testing"
"github.com/twmb/murmur3"
)
// We want to preserve backward compatibility
func TestHashBasic(t *testing.T) {
max_length := 1000
bigdata := make([]byte, max_length)
for i := 0; i < max_length; i++ {
bigdata[i] = byte(i)
}
for length := 0; length <= 1000; length++ {
data := bigdata[:length]
var d digest128
h1, h2, h3, h4 := d.sum256(data)
//
a1 := []byte{1} // to grab another bit of data
hasher := murmur3.New128()
hasher.Write(data) // #nosec
v1, v2 := hasher.Sum128()
hasher.Write(a1) // #nosec
v3, v4 := hasher.Sum128()
if v1 != h1 || v2 != h2 || v3 != h3 || v4 != h4 {
t.Errorf("Backward compatibillity break.")
}
}
}
func TestDocumentation(t *testing.T) {
filter := NewWithEstimates(10000, 0.01)
got := EstimateFalsePositiveRate(filter.m, filter.k, 10000)
if got > 0.011 || got < 0.009 {
t.Errorf("Bad false positive rate %v", got)
}
}
// We want to preserve backward compatibility
func TestHashRandom(t *testing.T) {
max_length := 1000
bigdata := make([]byte, max_length)
for length := 0; length <= 1000; length++ {
data := bigdata[:length]
for trial := 1; trial < 10; trial++ {
rand.Read(data)
var d digest128
h1, h2, h3, h4 := d.sum256(data)
//
a1 := []byte{1} // to grab another bit of data
hasher := murmur3.New128()
hasher.Write(data) // #nosec
v1, v2 := hasher.Sum128()
hasher.Write(a1) // #nosec
v3, v4 := hasher.Sum128()
if v1 != h1 || v2 != h2 || v3 != h3 || v4 != h4 {
t.Errorf("Backward compatibillity break.")
}
}
}
}