zip_test.go 737 B

1234567891011121314151617181920212223242526
  1. package help
  2. import "testing"
  3. func TestZip(t *testing.T) {
  4. input1 := []int{1, 2, 3}
  5. input2 := []int{2, 4, 5, 1}
  6. want := []interface{}{3, 6, 8}
  7. if q := From(input1).Zip(From(input2), func(i, j interface{}) interface{} {
  8. return i.(int) + j.(int)
  9. }); !validateQuery(q, want) {
  10. t.Errorf("From(%v).Zip(%v)=%v expected %v", input1, input2, toSlice(q), want)
  11. }
  12. }
  13. func TestZipT_PanicWhenResultSelectorFnIsInvalid(t *testing.T) {
  14. mustPanicWithError(t, "ZipT: parameter [resultSelectorFn] has a invalid function signature. Expected: 'func(T,T)T', actual: 'func(int,int,int)int'", func() {
  15. input1 := []int{1, 2, 3}
  16. input2 := []int{2, 4, 5, 1}
  17. From(input1).ZipT(From(input2), func(i, j, k int) int {
  18. return i + j
  19. })
  20. })
  21. }