Add expanded fuzz testing to algo_test.go

This commit introduces several new fuzz tests to the algo_test.go file. These tests specifically target the IntToAlgo functionality to ensure proper handling of negative, out-of-range, and very large input values. By covering these edge-cases, we enhance the reliability of the algorithm conversion process.
This commit is contained in:
Winni Neessen 2024-03-17 22:05:35 +01:00
parent f5f6a12e83
commit b40b4b7e63
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

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)
}
}
})
}