Skip to content

Commit

Permalink
more fuzz setup
Browse files Browse the repository at this point in the history
  • Loading branch information
alicebob committed Oct 4, 2023
1 parent 330352d commit e9a11f3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fpconv/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package fpconv

import (
"math"
"strconv"
"testing"
)
Expand All @@ -13,6 +14,9 @@ func FuzzDtoa(f *testing.F) {
f.Add(0.0)
f.Add(2.5339988685347402e-65)
f.Add(3.1415)
f.Add(math.Inf(1))
f.Add(math.Inf(-1))
f.Add(math.NaN())

f.Fuzz(func(t *testing.T, orig float64) {
s := Dtoa(orig)
Expand All @@ -23,6 +27,16 @@ func FuzzDtoa(f *testing.F) {
if err != nil {
t.Errorf("parse failed: %s", err)
}
if math.IsNaN(orig) {
if !math.IsNaN(n) {
t.Error("not NaN")
}
return
}

if math.IsNaN(n) {
t.Error("got NaN")
}
if n != orig {
t.Errorf("changed %f -> %f", n, orig)
}
Expand Down

0 comments on commit e9a11f3

Please sign in to comment.