test: add Drop to fuzz test, add drop test cases
This commit is contained in:
@@ -3,6 +3,7 @@ package cuckoo_test
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"maps"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -23,27 +24,45 @@ func FuzzInsertLookup(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, data []byte, seedA, seedB uint32) {
|
||||
assert := assert.New(t)
|
||||
|
||||
table := cuckoo.NewCustomTable[uint32, uint32](
|
||||
actual := cuckoo.NewCustomTable[uint32, uint32](
|
||||
offsetHash(seedA),
|
||||
offsetHash(seedB),
|
||||
func(a, b uint32) bool { return a == b },
|
||||
)
|
||||
|
||||
expected := map[uint32]uint32{}
|
||||
|
||||
if seedA == seedB {
|
||||
return
|
||||
}
|
||||
|
||||
r := bytes.NewReader(data)
|
||||
var key, value uint32
|
||||
var drop bool
|
||||
for binary.Read(r, binary.LittleEndian, &key) == nil &&
|
||||
binary.Read(r, binary.LittleEndian, &value) == nil {
|
||||
|
||||
err := table.Put(key, value)
|
||||
assert.NoError(err)
|
||||
if drop {
|
||||
err := actual.Drop(key)
|
||||
assert.NoError(err)
|
||||
|
||||
found, err := table.Get(key)
|
||||
assert.NoError(err)
|
||||
assert.Equal(value, found)
|
||||
delete(expected, key)
|
||||
|
||||
_, err = actual.Get(key)
|
||||
assert.Error(err)
|
||||
} else {
|
||||
err := actual.Put(key, value)
|
||||
assert.NoError(err)
|
||||
|
||||
expected[key] = value
|
||||
|
||||
found, err := actual.Get(key)
|
||||
assert.NoError(err)
|
||||
assert.Equal(value, found)
|
||||
}
|
||||
assert.Equal(expected, maps.Collect(actual.Entries()))
|
||||
|
||||
drop = !drop
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user