summaryrefslogtreecommitdiffstats
path: root/tpl/math/math_test.go
diff options
context:
space:
mode:
authorChris Dennis <ssa@fbcs.co.uk>2020-02-24 22:45:04 +0000
committerGitHub <noreply@github.com>2020-02-24 23:45:04 +0100
commitd184e5059c72c15df055192b01da0fd8c5b0fc5c (patch)
tree02cc841727b6b76fd57c852c8326153454f81811 /tpl/math/math_test.go
parent322c285ba2f3aa95826fe2135646b4d35f4d2a30 (diff)
tpl: Add math.Sqrt
Fixes #6941
Diffstat (limited to 'tpl/math/math_test.go')
-rw-r--r--tpl/math/math_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/tpl/math/math_test.go b/tpl/math/math_test.go
index 0beec8204..70f6749ba 100644
--- a/tpl/math/math_test.go
+++ b/tpl/math/math_test.go
@@ -153,6 +153,51 @@ func TestLog(t *testing.T) {
c.Assert(err, qt.IsNil)
c.Assert(result, qt.Equals, test.expect)
}
+
+ // Separate test for Log(-1) -- returns NaN
+ result, err := ns.Log(-1)
+ c.Assert(err, qt.IsNil)
+ c.Assert(result, qt.Satisfies, math.IsNaN)
+}
+
+func TestSqrt(t *testing.T) {
+ t.Parallel()
+ c := qt.New(t)
+
+ ns := New()
+
+ for _, test := range []struct {
+ a interface{}
+ expect interface{}
+ }{
+ {81, float64(9)},
+ {0.25, float64(0.5)},
+ {0, float64(0)},
+ {"abc", false},
+ } {
+
+ result, err := ns.Sqrt(test.a)
+
+ if b, ok := test.expect.(bool); ok && !b {
+ c.Assert(err, qt.Not(qt.IsNil))
+ continue
+ }
+
+ // we compare only 4 digits behind point if its a real float
+ // otherwise we usually get different float values on the last positions
+ if result != math.Inf(-1) {
+ result = float64(int(result*10000)) / 10000
+ }
+
+ c.Assert(err, qt.IsNil)
+ c.Assert(result, qt.Equals, test.expect)
+ }
+
+ // Separate test for Sqrt(-1) -- returns NaN
+ result, err := ns.Sqrt(-1)
+ c.Assert(err, qt.IsNil)
+ c.Assert(result, qt.Satisfies, math.IsNaN)
+
}
func TestMod(t *testing.T) {