|
1 |
| -import { concat, filter, map, reduce } from '../../../src/util/IterableUtil'; |
| 1 | +import { concat, filter, find, map, reduce } from '../../../src/util/IterableUtil'; |
2 | 2 |
|
3 | 3 | describe('IterableUtil', (): void => {
|
4 |
| - describe('#mapIterable', (): void => { |
| 4 | + describe('#map', (): void => { |
5 | 5 | it('maps the values to a new iterable.', async(): Promise<void> => {
|
6 | 6 | const input = [ 1, 2, 3 ];
|
7 | 7 | expect([ ...map(input, (val): number => val + 3) ]).toEqual([ 4, 5, 6 ]);
|
8 | 8 | });
|
9 | 9 | });
|
10 | 10 |
|
11 |
| - describe('#filterIterable', (): void => { |
| 11 | + describe('#filter', (): void => { |
12 | 12 | it('filters the values of the iterable.', async(): Promise<void> => {
|
13 | 13 | const input = [ 1, 2, 3 ];
|
14 | 14 | expect([ ...filter(input, (val): boolean => val % 2 === 1) ]).toEqual([ 1, 3 ]);
|
15 | 15 | });
|
16 | 16 | });
|
17 | 17 |
|
18 |
| - describe('#concatIterables', (): void => { |
| 18 | + describe('#concat', (): void => { |
19 | 19 | it('concatenates all the iterables.', async(): Promise<void> => {
|
20 | 20 | const input = [[ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]];
|
21 | 21 | expect([ ...concat(input) ]).toEqual([ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]);
|
22 | 22 | });
|
23 | 23 | });
|
24 | 24 |
|
25 |
| - describe('#reduceIterable', (): void => { |
| 25 | + describe('#find', (): void => { |
| 26 | + it('finds the matching value.', async(): Promise<void> => { |
| 27 | + const input = [[ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]; |
| 28 | + expect(find(input, (entry): boolean => entry.includes(5))).toEqual([ 4, 5, 6 ]); |
| 29 | + }); |
| 30 | + |
| 31 | + it('returns undefined if there is no match.', async(): Promise<void> => { |
| 32 | + const input = [[ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]; |
| 33 | + expect(find(input, (entry): boolean => entry.includes(0))).toBeUndefined(); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('#reduce', (): void => { |
26 | 38 | it('reduces the values in an iterable.', async(): Promise<void> => {
|
27 | 39 | const input = [ 1, 2, 3 ];
|
28 | 40 | expect(reduce(input, (acc, cur): number => acc + cur)).toBe(6);
|
|
0 commit comments