-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathempty.ts
More file actions
42 lines (34 loc) · 1.13 KB
/
empty.ts
File metadata and controls
42 lines (34 loc) · 1.13 KB
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
import test from 'ava';
import { ComparatorFn, numericCompare } from '@frptools/corelib';
import { empty, set, size, SortedMapEntry, firstValue, lastValue } from '../../src';
interface Item {
id: number;
time: number;
}
test('returns a map with size 0', t => {
t.is(size(empty()), 0);
});
test('always returns the same set instance if called with no arguments', t => {
const a = empty(), b = empty();
t.is(a, b);
});
test('sorts added items', t => {
const compare: ComparatorFn<SortedMapEntry<number, Item, number>> = (x, y) => numericCompare(x.view, y.view);
const map = empty<number, Item, number>(true, compare, x => x.time);
const now = new Date();
for (let i = 0; i < 15; i++) {
const item = {
id: (i + 1),
time: new Date(now.getFullYear(), now.getMonth(), now.getDate() - (i + 1)).valueOf()
};
set(item.id, item, map);
}
t.deepEqual(firstValue(map), {
id: 15,
time: new Date(now.getFullYear(), now.getMonth(), now.getDate() - 15).valueOf()
});
t.deepEqual(lastValue(map), {
id: 1,
time: new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1).valueOf()
});
});