testing/protobuf: fix float comparison bug
The prior code was comparing a to a, when it should compare a to b.
While we're at it, split the float32 and float64 cases apart to
ensure that the type provided by the implementation under test
really was the right float type. This matches the behavior of the
default case (which check that the types exactly match).
Change-Id: I01b1ff5b7f312a35cc8d1f012f3f747db26379fd
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/178377
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/testing/prototest/prototest.go b/testing/prototest/prototest.go
index c24a811..b5053f4 100644
--- a/testing/prototest/prototest.go
+++ b/testing/prototest/prototest.go
@@ -393,9 +393,12 @@
return equal
case []byte:
return bytes.Equal(a.Bytes(), b.Bytes())
- case float32, float64:
+ case float32:
// NaNs are equal, but must be the same NaN.
- return math.Float64bits(a.Float()) == math.Float64bits(a.Float())
+ return math.Float32bits(ai.(float32)) == math.Float32bits(bi.(float32))
+ case float64:
+ // NaNs are equal, but must be the same NaN.
+ return math.Float64bits(ai.(float64)) == math.Float64bits(bi.(float64))
default:
return ai == bi
}