feat: add options to fuzz testing
- Added the options to `fuzzScenario`. - They are clamped to non-panic values, so it only tests viable combinations.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package cuckoo_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"math"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -25,8 +28,10 @@ type fuzzStep struct {
|
||||
}
|
||||
|
||||
type fuzzScenario struct {
|
||||
seedA, seedB uint32
|
||||
steps []fuzzStep
|
||||
seedA, seedB uint32
|
||||
capacity, growthFactor uint8
|
||||
load float64
|
||||
steps []fuzzStep
|
||||
}
|
||||
|
||||
func FuzzInsertLookup(f *testing.F) {
|
||||
@@ -44,10 +49,21 @@ func FuzzInsertLookup(f *testing.F) {
|
||||
return
|
||||
}
|
||||
|
||||
seedA, seedB := scenario.seedA, scenario.seedB
|
||||
growthFactor := max(1, int(scenario.growthFactor))
|
||||
capacity := int(scenario.capacity)
|
||||
minimumLoad := math.Abs(math.Mod(scenario.load, 1.0))
|
||||
|
||||
fmt.Fprintf(os.Stderr, "seedA=%d seedB=%d capacity=%d growthFactor=%d minimumLoad=%f\n",
|
||||
seedA, seedB, capacity, growthFactor, minimumLoad)
|
||||
|
||||
actual := cuckoo.NewCustomTable[uint32, uint32](
|
||||
offsetHash(scenario.seedA),
|
||||
offsetHash(scenario.seedB),
|
||||
offsetHash(seedA),
|
||||
offsetHash(seedB),
|
||||
func(a, b uint32) bool { return a == b },
|
||||
cuckoo.Capacity(capacity),
|
||||
cuckoo.GrowthFactor(growthFactor),
|
||||
cuckoo.MinimumLoad(minimumLoad),
|
||||
)
|
||||
|
||||
expected := map[uint32]uint32{}
|
||||
|
||||
Reference in New Issue
Block a user