-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathasync_zip_sequence_test.go
More file actions
103 lines (84 loc) · 2.71 KB
/
async_zip_sequence_test.go
File metadata and controls
103 lines (84 loc) · 2.71 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package co_test
import (
"testing"
"github.com/smartystreets/goconvey/convey"
"go.tempura.ink/co"
)
func checkZip[T comparable](c convey.C, a [][]T, l ...[]T) {
cs := make([][]T, len(l))
for _, v := range a {
for i := range l {
cs[i] = append(cs[i], v[i])
}
}
for i := range l {
c.So(cs[i], convey.ShouldResemble, l[i])
}
}
func TestAsyncZip2Sequence(t *testing.T) {
convey.Convey("given a sequential int", t, func(c convey.C) {
list1 := []int{1, 2, 3, 4, 5}
aList := co.OfListWith(list1...)
mList := co.NewAsyncMapSequence[int](aList, func(v int) int {
return v
})
list2 := []int{1, 2, 3, 4, 5}
aList2 := co.OfListWith(list2...)
pList := co.Zip[int, int](mList, aList2)
convey.Convey("expect resolved list to be identical with given values \n", func() {
actual := [][]int{}
for data := range pList.Iter() {
actual = append(actual, []int{data.V1, data.V2})
}
convey.Printf("resulted list :: %+v \n", actual)
checkZip(c, actual, list1, list2)
})
})
}
func TestAsyncZip2SequenceWithDifferentLength(t *testing.T) {
convey.Convey("given a sequential int", t, func(c convey.C) {
list1 := []int{1, 2, 3, 4, 5, 6, 7, 8}
aList := co.OfListWith(list1...)
mList := co.NewAsyncMapSequence[int](aList, func(v int) int {
return v + 1
})
list2 := []int{1, 2, 3, 4, 5}
aList2 := co.OfListWith(list2...)
pList := co.Zip[int, int](mList, aList2)
convey.Convey("expect resolved list to be identical with given values \n", func() {
expected1 := []int{2, 3, 4, 5, 6, 7, 8, 9}
expected2 := []int{1, 2, 3, 4, 5, 5, 5, 5}
actual := [][]int{}
for data := range pList.Iter() {
actual = append(actual, []int{data.V1, data.V2})
}
convey.Printf("resulted list :: %+v \n", actual)
checkZip(c, actual, expected1, expected2)
})
})
}
func TestAsyncZip3Sequence(t *testing.T) {
convey.Convey("given a sequential int", t, func(c convey.C) {
list1 := []int{1, 2, 3, 4, 5}
aList := co.OfListWith(list1...)
mList := co.NewAsyncMapSequence[int](aList, func(v int) int {
return v + 1
})
list2 := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
aList2 := co.OfListWith(list2...)
list3 := []int{1, 2, 3, 4, 5, 6, 7}
aList3 := co.OfListWith(list3...)
pList := co.Zip3[int, int, int](mList, aList2, aList3)
convey.Convey("expect resolved list to be identical with given values \n", func() {
expected1 := []int{2, 3, 4, 5, 6, 6, 6, 6, 6}
expected2 := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
expected3 := []int{1, 2, 3, 4, 5, 6, 7, 7, 7}
actual := [][]int{}
for data := range pList.Iter() {
actual = append(actual, []int{data.V1, data.V2, data.V3})
}
convey.Printf("resulted list %+v \n", actual)
checkZip(c, actual, expected1, expected2, expected3)
})
})
}