-
Notifications
You must be signed in to change notification settings - Fork 0
/
converge_test.go
72 lines (66 loc) · 1.18 KB
/
converge_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
61
62
63
64
65
66
67
68
69
70
71
72
package pipe_test
import (
"testing"
"github.com/hsfzxjy/pipe"
"github.com/stretchr/testify/assert"
)
func TestConverge2(t *testing.T) {
a := make(chan int)
b := make(chan string)
c := pipe.Converge2(a, b)
go func() {
a <- 42
b <- "foo"
close(a)
close(b)
}()
assert.Equal(t, 42, <-c)
assert.Equal(t, "foo", <-c)
_, ok := <-c
assert.False(t, ok)
}
func TestConverge3(t *testing.T) {
a := make(chan int)
b := make(chan string)
c := make(chan float32)
d := pipe.Converge3(a, b, c)
go func() {
a <- 42
b <- "foo"
c <- 3.14
close(a)
close(b)
close(c)
}()
assert.Equal(t, 42, <-d)
assert.Equal(t, "foo", <-d)
assert.Equal(t, float32(3.14), <-d)
_, ok := <-d
assert.False(t, ok)
}
func TestConvergeN(t *testing.T) {
a := make(chan int)
b := make(chan string)
c := make(chan float32)
d := make(chan byte)
r := pipe.ConvergeN(a, b, c, d)
go func() {
a <- 42
b <- "foo"
c <- 3.14
d <- 1
close(a)
close(b)
close(c)
close(d)
}()
assert.Equal(t, 42, <-r)
assert.Equal(t, "foo", <-r)
assert.Equal(t, float32(3.14), <-r)
assert.Equal(t, byte(1), <-r)
}
func TestConverge0(t *testing.T) {
r := pipe.ConvergeN()
_, ok := <-r
assert.False(t, ok)
}