-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcompressor.test.ts
More file actions
49 lines (46 loc) · 1.26 KB
/
compressor.test.ts
File metadata and controls
49 lines (46 loc) · 1.26 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
43
44
45
46
47
48
49
import { divide2Buckets, GistData, gistData2Rows } from "@service/backup/gist/compressor"
test('divide 1', () => {
const rows: timer.core.Row[] = [{
host: 'www.baidu.com',
date: '20220801',
focus: 0,
time: 10,
}, {
host: 'www.baidu.com',
// Invalid date, count be compress
date: '',
focus: 0,
time: 10,
}]
const divided = divide2Buckets(rows)
expect(divided.length).toEqual(1)
const [bucket, gistData] = divided[0]
expect(bucket).toEqual('202208')
const expectData: GistData = {
"01": {
"www.baidu.com": [10, 0]
}
}
expect(gistData).toEqual(expectData)
})
test('gistData2Rows', () => {
const gistData: GistData = {
'01': {
'baidu.com': [0, 1]
},
'08': {
'google.com': [1, 1]
}
}
const rows = gistData2Rows('202209', gistData)
expect(rows.length).toEqual(2)
rows.sort((a, b) => a.date > b.date ? 1 : -1)
const row0 = rows[0]
const row1 = rows[1]
expect(row0.date).toEqual('20220901')
expect(row0.time).toEqual(0)
expect(row0.focus).toEqual(1)
expect(row1.date).toEqual('20220908')
expect(row1.time).toEqual(1)
expect(row1.focus).toEqual(1)
})