From: Russ Cox Date: Mon, 13 Feb 2012 04:24:54 +0000 (-0500) Subject: strconv: add tests for issue 2917 X-Git-Tag: weekly.2012-02-14~95 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f7a3683928fcfdcc0c7432b7d553b18627e40a50;p=gostls13.git strconv: add tests for issue 2917 Cannot reproduce the failure locally, but add explicit test in case some other machine can. Fixes #2917 (for now). R=golang-dev, r CC=golang-dev https://golang.org/cl/5651071 --- diff --git a/src/pkg/strconv/atof_test.go b/src/pkg/strconv/atof_test.go index 72cea49256..1da8c84d55 100644 --- a/src/pkg/strconv/atof_test.go +++ b/src/pkg/strconv/atof_test.go @@ -226,6 +226,40 @@ func TestAtofRandom(t *testing.T) { t.Logf("tested %d random numbers", len(atofRandomTests)) } +var roundTripCases = []struct { + f float64 + s string +}{ + // Issue 2917. + // A Darwin/386 builder failed on AtofRandom with this case. + {8865794286000691 << 39, "4.87402195346389e+27"}, + {8865794286000692 << 39, "4.8740219534638903e+27"}, +} + +func TestRoundTrip(t *testing.T) { + for _, tt := range roundTripCases { + old := SetOptimize(false) + s := FormatFloat(tt.f, 'g', -1, 64) + if s != tt.s { + t.Errorf("no-opt FormatFloat(%b) = %s, want %s", tt.f, s, tt.s) + } + f, err := ParseFloat(tt.s, 64) + if f != tt.f || err != nil { + t.Errorf("no-opt ParseFloat(%s) = %b, %v want %b, nil", tt.s, f, err, tt.f) + } + SetOptimize(true) + s = FormatFloat(tt.f, 'g', -1, 64) + if s != tt.s { + t.Errorf("opt FormatFloat(%b) = %s, want %s", tt.f, s, tt.s) + } + f, err = ParseFloat(tt.s, 64) + if f != tt.f || err != nil { + t.Errorf("opt ParseFloat(%s) = %b, %v want %b, nil", tt.s, f, err, tt.f) + } + SetOptimize(old) + } +} + func BenchmarkAtof64Decimal(b *testing.B) { for i := 0; i < b.N; i++ { ParseFloat("33909", 64)