summaryrefslogtreecommitdiffstats
path: root/tpl/math/math_test.go
diff options
context:
space:
mode:
authorOleksandr Redko <Oleksandr_Redko@epam.com>2023-05-16 19:32:07 +0300
committerGitHub <noreply@github.com>2023-05-16 18:32:07 +0200
commitbda082c98c7a0abdb019f12bb21cbaa7b0e8f60e (patch)
tree264dad483cd16238fa1864c7c3f127d4f72d24f4 /tpl/math/math_test.go
parent241b21b0fd34d91fccb2ce69874110dceae6f926 (diff)
tpl: Add math.Abs
Fixes #10941.
Diffstat (limited to 'tpl/math/math_test.go')
-rw-r--r--tpl/math/math_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/tpl/math/math_test.go b/tpl/math/math_test.go
index 3e83405fd..fad86938d 100644
--- a/tpl/math/math_test.go
+++ b/tpl/math/math_test.go
@@ -63,6 +63,33 @@ func TestBasicNSArithmetic(t *testing.T) {
}
}
+func TestAbs(t *testing.T) {
+ t.Parallel()
+ c := qt.New(t)
+ ns := New()
+
+ for _, test := range []struct {
+ x any
+ expect any
+ }{
+ {0.0, 0.0},
+ {1.5, 1.5},
+ {-1.5, 1.5},
+ {-2, 2.0},
+ {"abc", false},
+ } {
+ result, err := ns.Abs(test.x)
+
+ if b, ok := test.expect.(bool); ok && !b {
+ c.Assert(err, qt.Not(qt.IsNil))
+ continue
+ }
+
+ c.Assert(err, qt.IsNil)
+ c.Assert(result, qt.Equals, test.expect)
+ }
+}
+
func TestCeil(t *testing.T) {
t.Parallel()
c := qt.New(t)