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
|
package cuckoofilter
import (
"bufio"
"fmt"
"os"
"testing"
)
func TestInsertion(t *testing.T) {
cf := NewCuckooFilter(1000000)
fd, err := os.Open("/usr/share/dict/words")
if err != nil {
fmt.Println(err.Error())
return
}
scanner := bufio.NewScanner(fd)
var values [][]byte
var lineCount uint
for scanner.Scan() {
s := []byte(scanner.Text())
if cf.InsertUnique(s) {
lineCount++
}
values = append(values, s)
}
count := cf.Count()
if count != lineCount {
t.Errorf("Expected count = %d, instead count = %d", lineCount, count)
}
for _, v := range values {
cf.Delete(v)
}
count = cf.Count()
if count != 0 {
t.Errorf("Expected count = 0, instead count == %d", count)
}
}
|