aboutsummaryrefslogtreecommitdiff
path: root/src/math/big/float_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2015-03-03 14:17:39 -0800
committerRobert Griesemer <gri@golang.org>2015-03-04 18:24:34 +0000
commit2a1728d0094f0ffc66231ec415522bf54ca37293 (patch)
treedb38140b82a03b92f17dc4c7923c9faec13340d8 /src/math/big/float_test.go
parent0a8a62584870ef5b4eeea0f520d94d95235e4070 (diff)
downloadgo-2a1728d0094f0ffc66231ec415522bf54ca37293.tar.xz
math/big: use stringer for enum String() methods
Change-Id: Ide0615542d67b7d81bf6c56aab550e142a8789f7 Reviewed-on: https://go-review.googlesource.com/6682 Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/math/big/float_test.go')
-rw-r--r--src/math/big/float_test.go46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/math/big/float_test.go b/src/math/big/float_test.go
index aa1cb5828b..0be6a957d3 100644
--- a/src/math/big/float_test.go
+++ b/src/math/big/float_test.go
@@ -78,7 +78,7 @@ func TestFloatZeroValue(t *testing.T) {
z := make(test.z)
test.op(z, make(test.x), make(test.y))
got := 0
- if !z.IsInf(0) && !z.IsNaN() {
+ if z.IsFinite() {
got = int(z.int64())
}
if got != test.want {
@@ -288,6 +288,38 @@ func TestFloatSetMantExp(t *testing.T) {
}
}
+func TestFloatPredicates(t *testing.T) {
+ for _, test := range []struct {
+ x string
+ neg, zero, finite, inf, nan bool
+ }{
+ {x: "-Inf", neg: true, inf: true},
+ {x: "-1", neg: true, finite: true},
+ {x: "-0", neg: true, zero: true, finite: true},
+ {x: "0", zero: true, finite: true},
+ {x: "1", finite: true},
+ {x: "+Inf", inf: true},
+ {x: "NaN", nan: true},
+ } {
+ x := makeFloat(test.x)
+ if got := x.IsNeg(); got != test.neg {
+ t.Errorf("(%s).IsNeg() = %v; want %v", test.x, got, test.neg)
+ }
+ if got := x.IsZero(); got != test.zero {
+ t.Errorf("(%s).IsZero() = %v; want %v", test.x, got, test.zero)
+ }
+ if got := x.IsFinite(); got != test.finite {
+ t.Errorf("(%s).IsFinite() = %v; want %v", test.x, got, test.finite)
+ }
+ if got := x.IsInf(); got != test.inf {
+ t.Errorf("(%s).IsInf() = %v; want %v", test.x, got, test.inf)
+ }
+ if got := x.IsNaN(); got != test.nan {
+ t.Errorf("(%s).IsNaN() = %v; want %v", test.x, got, test.nan)
+ }
+ }
+}
+
func TestFloatIsInt(t *testing.T) {
for _, test := range []string{
"0 int",
@@ -314,14 +346,6 @@ func TestFloatIsInt(t *testing.T) {
}
}
-func TestFloatIsInf(t *testing.T) {
- // TODO(gri) implement this
-}
-
-func TestFloatIsNaN(t *testing.T) {
- // TODO(gri) implement this
-}
-
func fromBinary(s string) int64 {
x, err := strconv.ParseInt(s, 2, 64)
if err != nil {
@@ -740,10 +764,6 @@ func TestFloatSetInf(t *testing.T) {
}
}
-func TestFloatSetNaN(t *testing.T) {
- // TODO(gri) implement
-}
-
func TestFloatUint64(t *testing.T) {
for _, test := range []struct {
x string