-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrain_test.go
60 lines (55 loc) · 1.1 KB
/
drain_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package lazy
import (
"fmt"
"go4ml.xyz/fu"
"gotest.tools/v3/assert"
"testing"
)
func Test_Drain_1(t *testing.T) {
i := 0
List(colors).MustDrain(Sink(func(v interface{}, _ error) (_ error) {
if v != nil {
x := v.(Color)
assert.Assert(t, colors[i].Color == x.Color)
i++
} else {
assert.Assert(t, i == len(colors))
}
return
}))
}
func Test_Drain_2(t *testing.T) {
i := 0
List(colors).MustDrain(Sink(func(v interface{}, _ error) (_ error) {
if v != nil {
x := v.(Color)
assert.Assert(t, colors[i].Color == x.Color)
i++
} else {
assert.Assert(t, i == len(colors))
}
return
}), 8)
}
func Test_CcrDrain_1(t *testing.T) {
c := fu.AtomicCounter{}
List(colors).MustDrain(func(_ int) []Worker {
wrk := make([]Worker, 8) // concurrency = 8
for i := range wrk {
wrk[i] = func(i int, v interface{}, _ error) error {
if v != nil {
switch x := v.(type) {
case Color:
assert.Assert(t, colors[i].Color == x.Color)
i++
c.Inc()
}
}
return nil
}
}
return wrk
})
fmt.Println(c.Value)
assert.Assert(t, int(c.Value) == len(colors))
}