github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/math/abs_test.go (about) 1 package math_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/MontFerret/ferret/pkg/runtime/values" 8 "github.com/MontFerret/ferret/pkg/stdlib/math" 9 10 . "github.com/smartystreets/goconvey/convey" 11 ) 12 13 func TestAbs(t *testing.T) { 14 Convey("Should return absolute value", t, func() { 15 Convey("When value is int", func() { 16 out, err := math.Abs(context.Background(), values.NewInt(-5)) 17 18 So(err, ShouldBeNil) 19 So(out, ShouldEqual, 5) 20 21 out, err = math.Abs(context.Background(), values.NewInt(3)) 22 23 So(err, ShouldBeNil) 24 So(out, ShouldEqual, 3) 25 }) 26 27 Convey("When value is float", func() { 28 out, err := math.Abs(context.Background(), values.NewFloat(-5)) 29 30 So(err, ShouldBeNil) 31 So(out, ShouldEqual, 5) 32 33 out, err = math.Abs(context.Background(), values.NewFloat(5.1)) 34 35 So(err, ShouldBeNil) 36 So(out, ShouldEqual, 5.1) 37 }) 38 }) 39 }