-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
105 lines (100 loc) · 2.24 KB
/
test.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const test = require("ava");
const utils = require("./src/utils");
const GHmidi = require(".");
test("main file", async (t) => {
const result = await GHmidi("GMartigny");
t.true(result.length > 0);
await t.throwsAsync(() => GHmidi("github"));
});
test("fetch data", async (t) => {
const data = await utils.fetchData("GMartigny");
t.true(data.contributions.length > 0);
});
test("filter data", (t) => {
const now = new Date(Date.now() - (24 * 3600 * 1000));
const contributions = [
{
date: `${now.getFullYear() - 3}-${now.getMonth() + 1}-${now.getDate()}`,
},
{
date: `${now.getFullYear() - 1}-${now.getMonth() + 1}-${now.getDate()}`,
},
{
date: `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`,
},
{
date: `${now.getFullYear() + 1}-${now.getMonth() + 1}-${now.getDate()}`,
},
];
const filtered = utils.filterContributions(contributions, 368);
t.is(filtered.length, 2);
});
test("make notes", (t) => {
const data = [
{
intensity: 0,
},
{
intensity: 1,
},
{
intensity: 3,
},
{
intensity: 1,
},
{
intensity: 1,
},
{
intensity: 1,
},
{
intensity: 0,
},
{
intensity: 0,
},
{
intensity: 2,
},
];
const notes = utils.makeNotes(data, ["a", "b", "c", "d"]);
t.deepEqual(notes, ["a", "c", "a", "b"]);
t.throws(() => utils.makeNotes(data, ["a", "b", "c"]), {
instanceOf: RangeError,
});
});
test("make pattern", (t) => {
const data = [
{
intensity: 0,
},
{
intensity: 1,
},
{
intensity: 3,
},
{
intensity: 1,
},
{
intensity: 1,
},
{
intensity: 1,
},
{
intensity: 0,
},
{
intensity: 0,
},
{
intensity: 2,
},
];
const pattern = utils.makePattern(data);
t.is(pattern, "xxx__--x");
});