-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathzip-spec.ts
112 lines (85 loc) · 2.73 KB
/
zip-spec.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
import '../iterablehelpers';
import { sequenceEqual, throwError, zip } from 'ix/iterable/index.js';
test('Iterable#zip equal length', () => {
const xs = [1, 2, 3];
const ys = [4, 5, 6];
const res = zip(xs, ys);
const it = res[Symbol.iterator]();
let next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [1, 4])).toBeTruthy();
next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [2, 5])).toBeTruthy();
next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [3, 6])).toBeTruthy();
next = it.next();
expect(next.done).toBeTruthy();
});
test('Iterable#zip left longer', () => {
const xs = [1, 2, 3, 4];
const ys = [4, 5, 6];
const res = zip(xs, ys);
const it = res[Symbol.iterator]();
let next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [1, 4])).toBeTruthy();
next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [2, 5])).toBeTruthy();
next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [3, 6])).toBeTruthy();
next = it.next();
expect(next.done).toBeTruthy();
});
test('Iterable#zip right longer', () => {
const xs = [1, 2, 3];
const ys = [4, 5, 6, 7];
const res = zip(xs, ys);
const it = res[Symbol.iterator]();
let next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [1, 4])).toBeTruthy();
next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [2, 5])).toBeTruthy();
next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [3, 6])).toBeTruthy();
next = it.next();
expect(next.done).toBeTruthy();
});
test('Iterable#zip multiple sources', () => {
const xs = [1, 2, 3];
const ys = [4, 5, 6, 7];
const zs = [8, 9, 10];
const res = zip(xs, ys, zs);
const it = res[Symbol.iterator]();
let next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [1, 4, 8])).toBeTruthy();
next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [2, 5, 9])).toBeTruthy();
next = it.next();
expect(next.done).toBeFalsy();
expect(sequenceEqual(next.value, [3, 6, 10])).toBeTruthy();
next = it.next();
expect(next.done).toBeTruthy();
});
test('Iterable#zip left throws', () => {
const xs = throwError(new Error());
const ys = [4, 5, 6];
const res = zip(xs, ys);
const it = res[Symbol.iterator]();
expect(() => it.next()).toThrow();
});
test('Iterable#zip right throws', () => {
const xs = [1, 2, 3];
const ys = throwError(new Error());
const res = zip(xs, ys);
const it = res[Symbol.iterator]();
expect(() => it.next()).toThrow();
});