-
Notifications
You must be signed in to change notification settings - Fork 0
/
chronology.test.ts
47 lines (44 loc) · 1.48 KB
/
chronology.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import test from 'ava';
import Chronology from '../src/chronology';
import Datum from './datum.mock';
test('Chronology can group data by date', t => {
let data = [Datum()];
let c = new Chronology(data);
let date = data[0].moment.format('YYYY-MM-DD');
t.is([...c.byDate.keys()].length, 1);
let retrieved = c.byDate.get(date);
t.is(retrieved!.length, 1);
t.deepEqual(retrieved![0], data[0]);
});
test('Chronology can group data by hour', t => {
let data = [Datum()];
let c = new Chronology(data);
let keys = [...c.byHour.keys()];
t.is(keys.length, 24);
let hour = data[0].moment.hour();
let retrieved = c.byHour.get(hour);
t.is(retrieved!.length, 1);
t.deepEqual(retrieved![0], data[0]);
});
test('Chronology can group data by weekday', t => {
let data = [Datum()];
let c = new Chronology(data);
let keys = [...c.byWeekday.keys()];
t.is(keys.length, 7);
let weekday = data[0].moment.isoWeekday() - 1;
let retrieved = c.byWeekday.get(weekday);
t.is(retrieved!.length, 1);
t.deepEqual(retrieved![0], data[0]);
});
test('Chronology can group and nest data by hour for weekdays', t => {
let data = [Datum()];
let c = new Chronology(data);
let hour = data[0].moment.hour();
let weekday = data[0].moment.isoWeekday() - 1;
t.is([...c.byHourByWeekday.keys()].length, 7);
let hours = c.byHourByWeekday.get(weekday);
t.is([...hours!.keys()].length, 24);
let retrieved = hours!.get(hour);
t.is(retrieved!.length, 1);
t.deepEqual(retrieved![0], data[0]);
});