-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path10-19_integer_division_by_constant_reminder_test.go
67 lines (63 loc) · 1.64 KB
/
10-19_integer_division_by_constant_reminder_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
63
64
65
66
67
package hd_test
import (
"testing"
hd "github.com/nikolaydubina/go-hackers-delight"
)
func FuzzModUnsigned(f *testing.F) {
for _, u := range fuzzUint32 {
f.Add(u)
}
f.Fuzz(func(t *testing.T, x uint32) {
got := [...]struct {
exp uint32
got uint32
}{
{exp: x % 3, got: hd.Mod3Unsigned(x)},
{exp: x % 3, got: hd.Mod3Unsigned2(x)},
{exp: x % 3, got: hd.Mod3Unsigned3(x)},
{exp: x % 3, got: hd.Mod3Unsigned4(x)},
{exp: x % 3, got: hd.Mod3Unsigned5(x)},
{exp: x % 3, got: hd.Mod3Unsigned6(x)},
{exp: x % 5, got: hd.Mod5Unsigned(x)},
{exp: x % 5, got: hd.Mod5Unsigned2(x)},
{exp: x % 7, got: hd.Mod7Unsigned(x)},
{exp: x % 7, got: hd.Mod7Unsigned2(x)},
{exp: x % 9, got: hd.Mod9Unsigned(x)},
{exp: x % 9, got: hd.Mod9Unsigned2(x)},
{exp: x % 10, got: hd.Mod10Unsigned(x)},
{exp: x % 63, got: hd.Mod63Unsigned(x)},
{exp: x % 63, got: hd.Mod63Unsigned2(x)},
}
for i, tc := range got {
if tc.exp != tc.got {
t.Errorf("%d: tc(%v) x(%x)", i, tc, x)
}
}
})
}
func FuzzModSigned(f *testing.F) {
for _, u := range fuzzInt32 {
f.Add(u)
}
f.Fuzz(func(t *testing.T, x int32) {
got := [...]struct {
exp int32
got int32
}{
{exp: x % 3, got: hd.Mod3Signed(x)},
{exp: x % 3, got: hd.Mod3Signed2(x)},
{exp: x % 5, got: hd.Mod5Signed(x)},
{exp: x % 5, got: hd.Mod5Signed2(x)},
{exp: x % 7, got: hd.Mod7Signed(x)},
{exp: x % 7, got: hd.Mod7Signed2(x)},
{exp: x % 9, got: hd.Mod9Signed(x)},
{exp: x % 9, got: hd.Mod9Signed2(x)},
{exp: x % 10, got: hd.Mod10Signed(x)},
}
for i, tc := range got {
if tc.exp != tc.got {
t.Errorf("%d: tc(%v) x(%x)", i, tc, x)
}
}
})
}