mirror of
https://github.com/wneessen/apg-go.git
synced 2024-11-09 15:52:54 +01:00
commit
5ba220f1b9
2 changed files with 46 additions and 0 deletions
31
algo_test.go
31
algo_test.go
|
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue