(t *testing.T, dist func(input SimpleOutChannel, outputs ...SimpleInChannel))
| 154 | } |
| 155 | |
| 156 | func testDistribute(t *testing.T, dist func(input SimpleOutChannel, outputs ...SimpleInChannel)) { |
| 157 | a := NewNativeChannel(None) |
| 158 | b := NewNativeChannel(None) |
| 159 | |
| 160 | dist(a, b) |
| 161 | |
| 162 | testChannelPair(t, "simple distribute", a, b) |
| 163 | |
| 164 | a = NewNativeChannel(None) |
| 165 | outputs := []Channel{ |
| 166 | NewNativeChannel(None), |
| 167 | NewNativeChannel(None), |
| 168 | NewNativeChannel(None), |
| 169 | NewNativeChannel(None), |
| 170 | } |
| 171 | |
| 172 | dist(a, outputs[0], outputs[1], outputs[2], outputs[3]) |
| 173 | |
| 174 | go func() { |
| 175 | for i := 0; i < 1000; i++ { |
| 176 | a.In() <- i |
| 177 | } |
| 178 | a.Close() |
| 179 | }() |
| 180 | |
| 181 | received := make([]bool, 1000) |
| 182 | for _ = range received { |
| 183 | var val interface{} |
| 184 | select { |
| 185 | case val = <-outputs[0].Out(): |
| 186 | case val = <-outputs[1].Out(): |
| 187 | case val = <-outputs[2].Out(): |
| 188 | case val = <-outputs[3].Out(): |
| 189 | } |
| 190 | if received[val.(int)] { |
| 191 | t.Fatal("distribute got value twice", val.(int)) |
| 192 | } |
| 193 | received[val.(int)] = true |
| 194 | } |
| 195 | for i := range received { |
| 196 | if !received[i] { |
| 197 | t.Fatal("distribute missed", i) |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | func TestDistribute(t *testing.T) { |
| 203 | testDistribute(t, Distribute) |
no test coverage detected
searching dependent graphs…