-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple_lib.test.ts
32 lines (27 loc) · 932 Bytes
/
simple_lib.test.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
import {getList, map, reduce, writeAtIdx, makeIncrList} from './simple_lib';
test('should convert to and from regular lists', () => {
const l = makeIncrList([1, 2, 3]);
expect(getList(l)).toEqual([1, 2, 3]);
});
test('should map incrementally', () => {
const l = makeIncrList([1, 2, 3]);
const mapped = map(l, x => x * x);
expect(getList(mapped)).toEqual([1, 4, 9]);
});
test('should update map correctly', () => {
const l = makeIncrList([1, 2, 3]);
const mapped = map(l, x => x * x);
writeAtIdx(l, 1, 6);
expect(getList(mapped)).toEqual([1, 36, 9]);
});
test('should compute reduce correctly', () => {
const l = makeIncrList([1, 2, 3]);
const sum = reduce(l, (x, y) => x + y, 0);
expect(sum.value).toEqual(6);
});
test('should update reduce correctly', () => {
const l = makeIncrList([1, 2, 3]);
const sum = reduce(l, (x, y) => x + y, 0);
writeAtIdx(l, 1, 0);
expect(sum.value).toEqual(4);
});