-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuckoo_test.go
95 lines (78 loc) · 1.34 KB
/
cuckoo_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package cuckoo
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestHash(t *testing.T) {
size := 8
Init(size)
testData := []struct {
name string
data string
}{
{
name: "Test Hash -- test",
data: "test",
},
{
name: "Test Hash -- random",
data: "random",
},
}
for _, test := range testData {
fp := fingerprint(test.data)
a := hash(test.data)
b := a ^ hash(fp)
assert.NotEqual(t, a, b)
}
}
func TestInsert(t *testing.T) {
size := 500
Init(size)
for i := 0; i < size; i++ {
ok := Insert(string(i))
assert.True(t, ok)
}
}
func TestLookUp(t *testing.T) {
size := 500
Init(size)
for i := 0; i < size; i++ {
ok := Insert(string(i))
assert.True(t, ok)
}
for i := 0; i < size; i++ {
ok := LookUp(string(i))
assert.True(t, ok)
}
}
func TestLookUpFail(t *testing.T) {
size := 500
Init(size)
for i := 0; i < size; i++ {
ok := Insert(string(i))
assert.True(t, ok)
}
for i := size; i < 1000; i++ {
ok := LookUp(string(i))
assert.False(t, ok)
}
}
func TestDelete(t *testing.T) {
size := 100
Init(size)
ok := Insert("test")
assert.True(t, ok)
ok = LookUp("test")
assert.True(t, ok)
ok = Delete("test")
assert.True(t, ok)
ok = LookUp("test")
assert.False(t, ok)
}
func TestDeleteFail(t *testing.T) {
size := 100
Init(size)
ok := Delete("test")
assert.False(t, ok)
}