From b40b4b7e635a70603bec4bd36c8f381b87f030c0 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sun, 17 Mar 2024 22:05:35 +0100 Subject: [PATCH 1/2] 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. --- algo_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/algo_test.go b/algo_test.go index 992d6b9..faa3c98 100644 --- a/algo_test.go +++ b/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) + } + } + }) +} From 3ffb499c1bbe6462557426573cc4e1d15a1a7161 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sun, 17 Mar 2024 22:05:44 +0100 Subject: [PATCH 2/2] Add fuzz testing to config_test.go This commit adds a function `FuzzWithAlgorithm` to the configuration test file (config_test.go). The function introduces more comprehensive fuzz testing for the algorithm configuration. It focuses on handling different integers including negative and high numbers, thus enhancing robustness of the algorithm. --- config_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/config_test.go b/config_test.go index 4a8bab3..1f43cd2 100644 --- a/config_test.go +++ b/config_test.go @@ -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) + } + }) +}