-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
algo_test.go
62 lines (58 loc) · 1.4 KB
/
algo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-FileCopyrightText: 2021-2024 Winni Neessen <[email protected]>
//
// SPDX-License-Identifier: MIT
package apg
import (
"testing"
)
func TestIntToAlgo(t *testing.T) {
tt := []struct {
name string
a int
e Algorithm
}{
{"AlgoPronounceable", 0, AlgoPronounceable},
{"AlgoRandom", 1, AlgoRandom},
{"AlgoCoinflip", 2, AlgoCoinFlip},
{"AlgoBinary", 3, AlgoBinary},
{"AlgoUnsupported", 4, AlgoUnsupported},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
a := IntToAlgo(tc.a)
if a != tc.e {
t.Errorf("IntToAlgo() failed, expected: %d, got: %d", tc.e, a)
}
})
}
}
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)
}
}
})
}