-
Notifications
You must be signed in to change notification settings - Fork 11
/
async_combine_latest_sequence_test.go
96 lines (80 loc) · 2.62 KB
/
async_combine_latest_sequence_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package co_test
import (
"testing"
"github.com/smartystreets/goconvey/convey"
"go.tempura.ink/co"
"golang.org/x/exp/slices"
)
func checkCombineLatest[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(slices.Compact(cs[i]), convey.ShouldResemble, l[i])
}
}
func TestAsyncCombineLatest2Sequence(t *testing.T) {
convey.Convey("given a sequential int", t, func(c convey.C) {
numbers := []int{1, 2, 3, 4, 5}
aList := co.OfListWith(numbers...)
mList := co.NewAsyncMapSequence[int](aList, func(v int) int {
return v
})
numbers2 := []int{1, 2, 3, 4, 5}
aList2 := co.OfListWith(numbers2...)
pList := co.CombineLatest[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)
checkCombineLatest(c, actual, numbers, numbers2)
})
})
}
func TestAsyncCombineLatest2SequenceWithDifferentLength(t *testing.T) {
convey.Convey("given a sequential int", t, func(c convey.C) {
numbers := []int{1, 2, 3, 4, 5, 6, 7, 8}
aList := co.OfListWith(numbers...)
mList := co.NewAsyncMapSequence[int](aList, func(v int) int {
return v
})
numbers2 := []int{1, 2, 3, 4, 5}
aList2 := co.OfListWith(numbers2...)
pList := co.CombineLatest[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)
checkCombineLatest(c, actual, numbers, numbers2)
})
})
}
func TestAsyncCombineLatest3Sequence(t *testing.T) {
convey.Convey("given a sequential int", t, func(c convey.C) {
numbers := []int{1, 2, 3, 4, 5}
aList := co.OfListWith(numbers...)
mList := co.NewAsyncMapSequence[int](aList, func(v int) int {
return v
})
numbers2 := []int{1, 2, 3, 4, 5}
aList2 := co.OfListWith(numbers2...)
numbers3 := []int{1, 2, 3, 4, 5}
aList3 := co.OfListWith(numbers3...)
pList := co.CombineLatest3[int, int, int](mList, aList2, aList3)
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, data.V3})
}
convey.Printf("resulted list %+v \n", actual)
checkCombineLatest(c, actual, numbers, numbers2, numbers3)
})
})
}