Merge pull request #69 from wneessen/add_fuzzing

Add fuzzing
This commit is contained in:
Winni Neessen 2024-03-17 22:09:40 +01:00 committed by GitHub
commit 5ba220f1b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 0 deletions

View file

@ -29,3 +29,34 @@ func TestIntToAlgo(t *testing.T) {
})
}
}
func FuzzIntToAlgo(f *testing.F) {
f.Add(-1) // Test negative input
f.Add(4) // Test out-of-range positive input
f.Add(100) // Test very large input
f.Fuzz(func(t *testing.T, a int) {
algo := IntToAlgo(a)
switch a {
case 0:
if algo != AlgoPronounceable {
t.Errorf("IntToAlgo(%d) expected AlgoPronounceable, got %v", a, algo)
}
case 1:
if algo != AlgoRandom {
t.Errorf("IntToAlgo(%d) expected AlgoRandom, got %v", a, algo)
}
case 2:
if algo != AlgoCoinFlip {
t.Errorf("IntToAlgo(%d) expected AlgoCoinFlip, got %v", a, algo)
}
case 3:
if algo != AlgoBinary {
t.Errorf("IntToAlgo(%d) expected AlgoBinary, got %v", a, algo)
}
default:
if algo != AlgoUnsupported {
t.Errorf("IntToAlgo(%d) expected AlgoUnsupported, got %v", a, algo)
}
}
})
}

View file

@ -196,3 +196,18 @@ func TestWithModeMask(t *testing.T) {
e, c.Mode)
}
}
func FuzzWithAlgorithm(f *testing.F) {
f.Add(0)
f.Add(1)
f.Add(2)
f.Add(3)
f.Add(-1)
f.Add(100)
f.Fuzz(func(t *testing.T, algo int) {
config := NewConfig(WithAlgorithm(Algorithm(algo)))
if config.MaxLength < config.MinLength {
t.Errorf("Invalid algorithm: %d", algo)
}
})
}