-
Notifications
You must be signed in to change notification settings - Fork 18
/
Zip.ts
183 lines (134 loc) · 5.11 KB
/
Zip.ts
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { asAsync, itAsync, itEnumerable, itParallel } from "../TestHelpers"
describe("zip", () => {
itEnumerable<string | number>("Basic", (asEnumerable) => {
const it1 = [1, 2, 3, 4]
const it2 = ["5", "6", "7", "8"]
const zip = asEnumerable(it1).zip(asEnumerable(it2)).toArray()
expect(zip.length).toBe(it1.length)
for (let i = 0; i < zip.length; i++) {
const val = zip[i]
const first = it1[i]
const second = it2[i]
expect(val[0]).toBe(first)
expect(val[1]).toBe(second)
}
})
itAsync("Basic", async () => {
const it1 = [1, 2, 3, 4]
const it2 = ["5", "6", "7", "8"]
const it1Async = asAsync(it1)
const it2Async = asAsync(it2)
const zip = await it1Async.zip(it2Async).toArray()
expect(zip.length).toBe(it1.length)
for (let i = 0; i < zip.length; i++) {
const val = zip[i]
const first = it1[i]
const second = it2[i]
expect(val[0]).toBe(first)
expect(val[1]).toBe(second)
}
})
itParallel<string | number>("Basic", async (asParallel) => {
const it1 = [1, 2, 3, 4]
const it2 = ["5", "6", "7", "8"]
const it1Async = asParallel(it1)
const it2Async = asParallel(it2)
const zip = await it1Async.zip(it2Async).toArray()
expect(zip.length).toBe(it1.length)
for (let i = 0; i < zip.length; i++) {
const val = zip[i]
const first = it1[i]
const second = it2[i]
expect(val[0]).toBe(first)
expect(val[1]).toBe(second)
}
})
itEnumerable("zip selector", (asEnumerable) => {
const it1 = [1, 2, 3, 4]
const it2 = ["5", "6", "7", "8"]
const zip = asEnumerable(it1).zip(it2, (a, b) => ({ a, b })).toArray()
for (let i = 0; i < zip.length; i++) {
const val = zip[i]
const first = it1[i]
const second = it2[i]
expect(val.a).toBe(first)
expect(val.b).toBe(second)
}
})
itAsync("zip selector", async () => {
const it1 = [1, 2, 3, 4]
const it2 = ["5", "6", "7", "8"]
const it1Async = asAsync(it1)
const it2Async = asAsync(it2)
const zip = await it1Async.zip(it2Async, (a, b) => ({ a, b })).toArray()
for (let i = 0; i < zip.length; i++) {
const val = zip[i]
const first = it1[i]
const second = it2[i]
expect(val.a).toBe(first)
expect(val.b).toBe(second)
}
})
itParallel<string | number>("zip selector", async (asParallel) => {
const it1 = [1, 2, 3, 4]
const it2 = ["5", "6", "7", "8"]
const it1Async = asParallel(it1)
const it2Async = asParallel(it2)
const zip = await it1Async.zip(it2Async, (a, b) => ({ a, b })).toArray()
for (let i = 0; i < zip.length; i++) {
const val = zip[i]
const first = it1[i]
const second = it2[i]
expect(val.a).toBe(first)
expect(val.b).toBe(second)
}
})
itEnumerable("different sizes", (asEnumerable) => {
const it1 = asEnumerable([1, 2])
const it2 = asEnumerable([1, 2, 3])
const zip1 = it1.zip(it2).toArray()
expect(zip1.length).toBe(2)
const zip2 = it2.zip(it1).toArray()
expect(zip2.length).toBe(2)
})
itAsync("different sizes", async () => {
const it1 = asAsync([1, 2])
const it2 = asAsync([1, 2, 3])
const zip1 = await it1.zip(it2).toArray()
expect(zip1.length).toBe(2)
const zip2 = await it2.zip(it1).toArray()
expect(zip2.length).toBe(2)
})
itParallel("different sizes", async (asParallel) => {
const it1 = asParallel([1, 2])
const it2 = asParallel([1, 2, 3])
const zip1 = await it1.zip(it2).toArray()
expect(zip1.length).toBe(2)
const zip2 = await it2.zip(it1).toArray()
expect(zip2.length).toBe(2)
})
itEnumerable("different sizes selector", (asEnumerable) => {
const it1 = asEnumerable([1, 2])
const it2 = asEnumerable([1, 2, 3])
const zip1 = it1.zip(it2, (a, b) => [a, b]).toArray()
expect(zip1.length).toBe(2)
const zip2 = it2.zip(it1, (a, b) => [a, b]).toArray()
expect(zip2.length).toBe(2)
})
itAsync("different sizes selector", async () => {
const it1 = asAsync([1, 2])
const it2 = asAsync([1, 2, 3])
const zip1 = await it1.zip(it2, (a, b) => [a, b]).toArray()
expect(zip1.length).toBe(2)
const zip2 = await it2.zip(it1, (a, b) => [a, b]).toArray()
expect(zip2.length).toBe(2)
})
itParallel("different sizes selector", async (asParallel) => {
const it1 = asParallel([1, 2])
const it2 = asParallel([1, 2, 3])
const zip1 = await it1.zip(it2, (a, b) => [a, b]).toArray()
expect(zip1.length).toBe(2)
const zip2 = await it2.zip(it1, (a, b) => [a, b]).toArray()
expect(zip2.length).toBe(2)
})
})