-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbf_test.go
More file actions
58 lines (44 loc) · 1.06 KB
/
cbf_test.go
File metadata and controls
58 lines (44 loc) · 1.06 KB
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
package bloomfilter
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBasic(t *testing.T) {
cbf := NewCountingBloomFilter(100, 0.01)
cbf.Add([]byte("test1"))
cbf.Add([]byte("aaa"))
cbf.Add([]byte("another"))
assert.True(t, cbf.Exist([]byte("aaa")))
cbf.Remove([]byte("another"))
assert.False(t, cbf.Exist([]byte("another")))
}
func BenchmarkAdd(b *testing.B) {
cbf := NewCountingBloomFilter(100000, 0.01)
for i := 0; i < b.N; i++ {
element := []byte(strconv.Itoa(i))
cbf.Add(element)
}
}
func BenchmarkExist(b *testing.B) {
cbf := NewCountingBloomFilter(100000, 0.01)
for i := 0; i < 100000; i++ {
element := []byte(strconv.Itoa(i))
cbf.Add(element)
}
for i := 0; i < b.N; i++ {
element := []byte(strconv.Itoa(i % 100000))
cbf.Exist(element)
}
}
func BenchmarkRemove(b *testing.B) {
cbf := NewCountingBloomFilter(100000, 0.01)
for i := 0; i < 100000; i++ {
element := []byte(strconv.Itoa(i))
cbf.Add(element)
}
for i := 0; i < b.N; i++ {
element := []byte(strconv.Itoa(i % 100000))
cbf.Remove(element)
}
}