/
bloom_test.go
49 lines (40 loc) · 881 Bytes
/
bloom_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
package bloom
import (
"testing"
"rand"
)
const (
STORE_RUNS int = 200
RETRIEVE_RUNS int = 200
)
func TestStore(t *testing.T) {
bloom := New()
for i := 0; i < STORE_RUNS; i++ {
bloom.Add(string(rand.Uint32()))
}
}
func TestRetrieveTrue(t *testing.T) {
bloom := New()
var toAdd [RETRIEVE_RUNS]string
for i := 0; i < RETRIEVE_RUNS; i++ {
toAdd[i] = string(rand.Uint32())
bloom.Add(toAdd[i])
}
for i := 0; i < RETRIEVE_RUNS; i++ {
if !bloom.In(toAdd[i]) {
t.Error("BloomFilter.In returns false posative for string ", toAdd[i])
}
}
}
func TestRetrieveFalse(t *testing.T) {
bloom := New()
var toTest [RETRIEVE_RUNS]string
for i := 0; i < RETRIEVE_RUNS; i++ {
toTest[i] = string(rand.Uint32())
}
for i := 0; i < RETRIEVE_RUNS; i++ {
if bloom.In(toTest[i]) {
t.Error("BloomFilter.In returns false negative for string ", toTest[i])
}
}
}