-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathcommaf_fuzz_test.go
More file actions
49 lines (40 loc) · 1014 Bytes
/
Copy pathcommaf_fuzz_test.go
File metadata and controls
49 lines (40 loc) · 1014 Bytes
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
//go:build go1.18
// +build go1.18
package humanize_test
import (
"math"
"math/big"
"testing"
"github.com/dustin/go-humanize"
)
func FuzzBigCommaf(f *testing.F) {
f.Add(0.0)
f.Add(-1.0)
f.Add(10.11)
f.Add(-10.11)
f.Add(1234567.5)
f.Add(-1234567.5)
f.Add(math.MaxFloat64)
f.Add(-math.MaxFloat64)
f.Add(math.SmallestNonzeroFloat64)
f.Add(-math.SmallestNonzeroFloat64)
f.Add(math.Inf(1))
f.Add(math.Inf(-1))
f.Fuzz(func(t *testing.T, v float64) {
if math.IsNaN(v) {
t.Skip("big.Float cannot represent NaN")
}
in := big.NewFloat(v)
want := new(big.Float).Copy(in)
got := humanize.BigCommaf(in)
// BigCommaf must not modify its argument.
if in.Cmp(want) != 0 {
t.Fatalf("BigCommaf(%v) modified its argument: got %v, want %v", v, in, want)
}
// Calling it again on the same (unmodified) value should produce
// the same result.
if got2 := humanize.BigCommaf(in); got2 != got {
t.Fatalf("BigCommaf(%v) not idempotent: first %q, second %q", v, got, got2)
}
})
}