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

Function TestFilter

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

Source from the content-addressed store, hash-verified

91}
92
93func TestFilter(t *testing.T) {
94 th.TestBothOrderings(t, func(t *testing.T, ord bool) {
95 for _, n := range []int{1, 5} {
96
97 t.Run(th.Name("nil", n), func(t *testing.T) {
98 out := universalFilter(ord, nil, n, func(x int) (bool, error) { return true, nil })
99 th.ExpectValue(t, out, nil)
100 })
101
102 t.Run(th.Name("correctness", n), func(t *testing.T) {
103 in := FromChan(th.FromRange(0, 20), nil)
104 in = replaceWithError(in, 15, fmt.Errorf("err15"))
105
106 out := universalFilter(ord, in, n, func(x int) (bool, error) {
107 if x == 5 {
108 return false, fmt.Errorf("err05")
109 }
110 if x == 6 {
111 return true, fmt.Errorf("err06")
112 }
113
114 return x%2 == 0, nil
115 })
116
117 outSlice, errSlice := toSliceAndErrors(out)
118
119 expectedSlice := make([]int, 0, 20)
120 for i := 0; i < 20; i++ {
121 if i%2 == 1 || i == 5 || i == 6 || i == 15 {
122 continue
123 }
124 expectedSlice = append(expectedSlice, i)
125 }
126
127 th.Sort(outSlice)
128 th.Sort(errSlice)
129
130 th.ExpectSlice(t, outSlice, expectedSlice)
131 th.ExpectSlice(t, errSlice, []string{"err05", "err06", "err15"})
132 })
133
134 t.Run(th.Name("ordering", n), func(t *testing.T) {
135 in := FromChan(th.FromRange(0, 20000), nil)
136
137 out := universalFilter(ord, in, n, func(x int) (bool, error) {
138 switch x % 3 {
139 case 2:
140 return false, fmt.Errorf("err%06d", x)
141 case 1:
142 return false, nil
143 default:
144 return true, nil
145
146 }
147 })
148
149 outSlice, errSlice := toSliceAndErrors(out)
150

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected