MCPcopy
hub / github.com/destel/rill / TestMap

Function TestMap

transform_test.go:18–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16}
17
18func 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 {

Callers

nothing calls this directly

Calls 11

TestBothOrderingsFunction · 0.92
NameFunction · 0.92
ExpectValueFunction · 0.92
FromRangeFunction · 0.92
ExpectSliceFunction · 0.92
ExpectSortedFunction · 0.92
ExpectUnsortedFunction · 0.92
universalMapFunction · 0.85
FromChanFunction · 0.85
replaceWithErrorFunction · 0.85
toSliceAndErrorsFunction · 0.85

Tested by

no test coverage detected