github.com/panmari/cuckoofilter@v1.0.7-0.20231223155748-763d1d471ee8/cuckoofilter_fuzz_test.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 package cuckoo 5 6 import ( 7 "testing" 8 ) 9 10 func FuzzDecode(f *testing.F) { 11 cf := NewFilter(10) 12 cf.Insert([]byte{1}) 13 cf.Insert([]byte{2}) 14 cf.Insert([]byte{3}) 15 cf.Insert([]byte{4}) 16 cf.Insert([]byte{5}) 17 cf.Insert([]byte{6}) 18 cf.Insert([]byte{7}) 19 cf.Insert([]byte{8}) 20 cf.Insert([]byte{9}) 21 f.Add(cf.Encode()) 22 f.Fuzz(func(t *testing.T, encoded []byte) { 23 cache, err := Decode(encoded) 24 if err != nil { 25 // Construction failed, no need to test further. 26 return 27 } 28 cache.Lookup([]byte("hello")) 29 insertOk := cache.Insert([]byte("world")) 30 if del := cache.Delete([]byte("world")); insertOk && !del { 31 t.Errorf("Failed to delete item.") 32 } 33 }) 34 }