intersect_test.go 1019 B

123456789101112131415161718192021222324252627282930313233
  1. package help
  2. import "testing"
  3. func TestIntersect(t *testing.T) {
  4. input1 := []int{1, 2, 3}
  5. input2 := []int{1, 4, 7, 9, 12, 3}
  6. want := []interface{}{1, 3}
  7. if q := From(input1).Intersect(From(input2)); !validateQuery(q, want) {
  8. t.Errorf("From(%v).Intersect(%v)=%v expected %v", input1, input2, toSlice(q), want)
  9. }
  10. }
  11. func TestIntersectBy(t *testing.T) {
  12. input1 := []int{5, 7, 8}
  13. input2 := []int{1, 4, 7, 9, 12, 3}
  14. want := []interface{}{5, 8}
  15. if q := From(input1).IntersectBy(From(input2), func(i interface{}) interface{} {
  16. return i.(int) % 2
  17. }); !validateQuery(q, want) {
  18. t.Errorf("From(%v).IntersectBy(%v)=%v expected %v", input1, input2, toSlice(q), want)
  19. }
  20. }
  21. func TestIntersectByT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
  22. mustPanicWithError(t, "IntersectByT: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
  23. From([]int{5, 7, 8}).IntersectByT(From([]int{1, 4, 7, 9, 12, 3}), func(i, x int) int {
  24. return i % 2
  25. })
  26. })
  27. }