except_test.go 1005 B

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