github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/math/median_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 TestMedian(t *testing.T) { 14 Convey("Should return median value", t, func() { 15 out, err := math.Median(context.Background(), values.NewArrayWith( 16 values.NewInt(1), 17 values.NewInt(2), 18 values.NewInt(3), 19 )) 20 21 So(err, ShouldBeNil) 22 So(out, ShouldEqual, 2) 23 24 out, err = math.Average(context.Background(), values.NewArrayWith( 25 values.NewInt(1), 26 values.NewInt(2), 27 values.NewInt(3), 28 values.NewInt(4), 29 )) 30 31 So(err, ShouldBeNil) 32 So(out, ShouldEqual, 2.5) 33 34 out, err = math.Average(context.Background(), values.NewArrayWith( 35 values.NewInt(2), 36 values.NewInt(1), 37 values.NewInt(4), 38 values.NewInt(3), 39 )) 40 41 So(err, ShouldBeNil) 42 So(out, ShouldEqual, 2.5) 43 44 out, err = math.Average(context.Background(), values.NewArrayWith( 45 values.None, 46 values.NewInt(-5), 47 values.False, 48 )) 49 50 So(err, ShouldBeNil) 51 So(out, ShouldEqual, values.None) 52 }) 53 }