github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/arrays/outersection_test.go (about) 1 package arrays_test 2 3 import ( 4 "context" 5 "testing" 6 7 . "github.com/smartystreets/goconvey/convey" 8 9 "github.com/MontFerret/ferret/pkg/runtime/core" 10 "github.com/MontFerret/ferret/pkg/runtime/values" 11 "github.com/MontFerret/ferret/pkg/stdlib/arrays" 12 ) 13 14 func TestOutersection(t *testing.T) { 15 Convey("Should find intersections between 2 arrays", t, func() { 16 arr1 := values.NewArrayWith( 17 values.NewInt(1), 18 values.NewInt(2), 19 values.NewInt(3), 20 ) 21 22 arr2 := values.NewArrayWith( 23 values.NewInt(2), 24 values.NewInt(3), 25 values.NewInt(4), 26 ) 27 28 out, err := arrays.Outersection(context.Background(), arr1, arr2) 29 30 check := map[int]bool{ 31 1: true, 32 4: true, 33 } 34 35 So(err, ShouldBeNil) 36 37 arr := out.(*values.Array) 38 39 So(arr.Length(), ShouldEqual, 2) 40 41 arr.ForEach(func(value core.Value, idx int) bool { 42 _, exists := check[int(value.(values.Int))] 43 44 So(exists, ShouldBeTrue) 45 46 return true 47 }) 48 }) 49 50 Convey("Should find intersections between more than 2 arrays", t, func() { 51 arr1 := values.NewArrayWith( 52 values.NewInt(1), 53 values.NewInt(2), 54 values.NewInt(3), 55 ) 56 57 arr2 := values.NewArrayWith( 58 values.NewInt(2), 59 values.NewInt(3), 60 values.NewInt(4), 61 ) 62 63 arr3 := values.NewArrayWith( 64 values.NewInt(3), 65 values.NewInt(4), 66 values.NewInt(5), 67 ) 68 69 out, err := arrays.Outersection(context.Background(), arr1, arr2, arr3) 70 71 check := map[int]bool{ 72 1: true, 73 5: true, 74 } 75 76 So(err, ShouldBeNil) 77 78 arr := out.(*values.Array) 79 80 So(arr.Length(), ShouldEqual, 2) 81 82 arr.ForEach(func(value core.Value, idx int) bool { 83 _, exists := check[int(value.(values.Int))] 84 85 So(exists, ShouldBeTrue) 86 87 return true 88 }) 89 }) 90 }