-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathreduce-spec.ts
37 lines (31 loc) · 1.07 KB
/
reduce-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
import '../iterablehelpers';
import { of, empty, reduce } from 'ix/iterable/index.js';
test('Iterable#reduce no seed', () => {
const xs = of(0, 1, 2, 3, 4);
const ys = reduce(xs, { callback: (x, y, i) => x + y + i });
expect(ys).toBe(20);
});
test('Iterable#reduce no seed empty throws', () => {
const xs = empty();
expect(() => reduce<number>(xs, { callback: (x, y, i) => x + y + i })).toThrow();
});
test('Iterable#reduce with seed', () => {
const xs = of(0, 1, 2, 3, 4);
const ys = reduce(xs, { callback: (x, y, i) => x - y - i, seed: 20 });
expect(ys).toBe(0);
});
test('Iterable#reduce with seed empty', () => {
const xs = empty();
const ys = reduce(xs, { callback: (x, y, i) => x - y - i, seed: 20 });
expect(ys).toBe(20);
});
test('Iterable#reduce no seed Array signature', () => {
const xs = of(0, 1, 2, 3, 4);
const ys = reduce(xs, (x, y, i) => x + y + i);
expect(ys).toBe(20);
});
test('Iterable#reduce with seed Array signature', () => {
const xs = of(0, 1, 2, 3, 4);
const ys = reduce(xs, (x, y, i) => x - y - i, 20);
expect(ys).toBe(0);
});