]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: add tests for issue 2917
authorRuss Cox <rsc@golang.org>
Mon, 13 Feb 2012 04:24:54 +0000 (23:24 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 13 Feb 2012 04:24:54 +0000 (23:24 -0500)
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

src/pkg/strconv/atof_test.go

index 72cea492562d8f75a883fa9eeae43bd853b86475..1da8c84d55458f2d04174477e2755b7e1fd97a81 100644 (file)
@@ -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)