(t *testing.T)
| 16 | } |
| 17 | |
| 18 | func TestMap(t *testing.T) { |
| 19 | th.TestBothOrderings(t, func(t *testing.T, ord bool) { |
| 20 | for _, n := range []int{1, 5} { |
| 21 | |
| 22 | t.Run(th.Name("nil", n), func(t *testing.T) { |
| 23 | out := universalMap(ord, nil, n, func(x int) (int, error) { return x, nil }) |
| 24 | th.ExpectValue(t, out, nil) |
| 25 | }) |
| 26 | |
| 27 | t.Run(th.Name("correctness", n), func(t *testing.T) { |
| 28 | in := FromChan(th.FromRange(0, 20), nil) |
| 29 | in = replaceWithError(in, 15, fmt.Errorf("err15")) |
| 30 | |
| 31 | out := universalMap(ord, in, n, func(x int) (string, error) { |
| 32 | if x == 5 { |
| 33 | return "", fmt.Errorf("err05") |
| 34 | } |
| 35 | if x == 6 { |
| 36 | return "", fmt.Errorf("err06") |
| 37 | } |
| 38 | |
| 39 | return fmt.Sprintf("%03d", x), nil |
| 40 | }) |
| 41 | |
| 42 | outSlice, errSlice := toSliceAndErrors(out) |
| 43 | |
| 44 | expectedSlice := make([]string, 0, 20) |
| 45 | for i := 0; i < 20; i++ { |
| 46 | if i == 5 || i == 6 || i == 15 { |
| 47 | continue |
| 48 | } |
| 49 | expectedSlice = append(expectedSlice, fmt.Sprintf("%03d", i)) |
| 50 | } |
| 51 | |
| 52 | sort.Strings(outSlice) |
| 53 | sort.Strings(errSlice) |
| 54 | |
| 55 | th.ExpectSlice(t, outSlice, expectedSlice) |
| 56 | th.ExpectSlice(t, errSlice, []string{"err05", "err06", "err15"}) |
| 57 | }) |
| 58 | |
| 59 | t.Run(th.Name("ordering", n), func(t *testing.T) { |
| 60 | in := FromChan(th.FromRange(0, 20000), nil) |
| 61 | |
| 62 | out := universalMap(ord, in, n, func(x int) (int, error) { |
| 63 | if x%2 == 0 { |
| 64 | return x, fmt.Errorf("err%06d", x) |
| 65 | } |
| 66 | |
| 67 | return x, nil |
| 68 | }) |
| 69 | |
| 70 | outSlice, errSlice := toSliceAndErrors(out) |
| 71 | |
| 72 | if ord || n == 1 { |
| 73 | th.ExpectSorted(t, outSlice) |
| 74 | th.ExpectSorted(t, errSlice) |
| 75 | } else { |
nothing calls this directly
no test coverage detected