-
Notifications
You must be signed in to change notification settings - Fork 110
/
scalable_cuckoofilter_test.go
46 lines (42 loc) · 1.24 KB
/
scalable_cuckoofilter_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
package cuckoo
import (
"strconv"
"testing"
)
import "github.com/stretchr/testify/assert"
func TestNormalUse(t *testing.T) {
filter := NewScalableCuckooFilter()
for i := 0; i < 100000; i++ {
filter.Insert([]byte("NewScalableCuckooFilter_" + strconv.Itoa(i)))
}
testStr := []byte("NewScalableCuckooFilter")
b := filter.Insert(testStr)
assert.True(t, b)
b = filter.Lookup(testStr)
assert.True(t, b)
b = filter.Delete(testStr)
assert.True(t, b)
b = filter.Lookup(testStr)
assert.False(t, b)
b = filter.Lookup([]byte("NewScalableCuckooFilter_233"))
assert.True(t, b)
b = filter.InsertUnique([]byte("NewScalableCuckooFilter_599"))
assert.False(t, b)
}
func TestScalableCuckooFilter_DecodeEncode(t *testing.T) {
filter := NewScalableCuckooFilter(func(filter *ScalableCuckooFilter) {
filter.loadFactor = 0.8
})
for i := 0; i < 100000; i++ {
filter.Insert([]byte("NewScalableCuckooFilter_" + strconv.Itoa(i)))
}
bytes := filter.Encode()
decodeFilter, err := DecodeScalableFilter(bytes)
assert.Nil(t, err)
assert.Equal(t, decodeFilter.loadFactor, float32(0.8))
b := decodeFilter.Lookup([]byte("NewScalableCuckooFilter_233"))
assert.True(t, b)
for i, f := range decodeFilter.filters {
assert.Equal(t, f.count, filter.filters[i].count)
}
}