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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
local dates = require "activity.dates"
local generators = require "activity.generators"
local plain = require "activity.formats.plain"
local Y2024 = [[
_0000000000000000000000000000000000000000000000000000
Mon 00000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000
Wed 0000000000000000000000000000000000000000000000000000_
0000000000000000000000000000000000000000000000000000_
Fri 0000000000000000000000000000000000000000000000000000_
0000000000000000000000000000000000000000000000000000_
]]
local Y2023 = [[
00000000000000000000000000000000000000000000000000000
Mon 0000000000000000000000000000000000000000000000000000_
0000000000000000000000000000000000000000000000000000_
Wed 0000000000000000000000000000000000000000000000000000_
0000000000000000000000000000000000000000000000000000_
Fri 0000000000000000000000000000000000000000000000000000_
0000000000000000000000000000000000000000000000000000_
]]
local Y2020 = [[
_0000000000000000000000000000000000000000000000000000
Mon _0000000000000000000000000000000000000000000000000000
_0000000000000000000000000000000000000000000000000000
Wed 00000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000
Fri 0000000000000000000000000000000000000000000000000000_
0000000000000000000000000000000000000000000000000000_
]]
local ROLL = [[
00000000000000000000000000000000000000000000000000000
Mon 00000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000
Wed 00000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000
Fri 0000000000000000000000000000000000000000000000000000_
0000000000000000000000000000000000000000000000000000_
]]
local
function always_zero (...)
return 0
end
describe("Yearly chart generator", function()
describe("shall generate empty table for year", function()
it("2024", function()
assert.are.equal(Y2024, generators.generate_table(2024, always_zero, plain))
end)
it("2023", function()
assert.are.equal(Y2023, generators.generate_table(2023, always_zero, plain))
end)
it("2020", function()
assert.are.equal(Y2020, generators.generate_table(2020, always_zero, plain))
end)
end)
describe("shall put activity into cells for", function()
local function lookup (year, day)
if day < 1 or dates.days_in(year) < day then
return 0
end
return 1
end
it("regular years", function()
assert.are.equal(Y2023:gsub("0", "1"), generators.generate_table(2023, lookup, plain))
end)
it("leap years", function()
assert.are.equal(Y2024:gsub("0", "1"), generators.generate_table(2024, lookup, plain))
end)
end)
it("shall use entire format", function()
mock(plain)
_ = generators.generate_table(2023, always_zero, plain)
assert.spy(plain.start_document).was.called()
assert.spy(plain.start_table).was.called()
assert.spy(plain.start_row).was.called()
assert.spy(plain.label).was.called(7)
assert.spy(plain.spot).was.called(6)
assert.spy(plain.cell).was.called(365)
assert.spy(plain.end_row).was.called()
assert.spy(plain.end_table).was.called()
assert.spy(plain.end_document).was.called()
mock.revert(plain)
end)
end)
describe("Rolling chart generator", function()
local date = os.date("*t", os.time{year=2024, month=2, day=8})
it("shall generate empty table", function()
assert.are.equal(ROLL, generators.generate_table("rolling", always_zero, plain, date))
end)
it("shall put activity into cells", function()
local function lookup (year, day)
if year == 2023 and day >= 36 then
return 1
end
if year == 2024 and day <= 39 then
return 1
end
return 0
end
assert.are.equal(ROLL:gsub("0", "1"), generators.generate_table("rolling", lookup, plain, date))
end)
it("shall use entire format", function()
mock(plain)
_ = generators.generate_table("rolling", always_zero, plain, date)
assert.spy(plain.start_document).was.called()
assert.spy(plain.start_table).was.called()
assert.spy(plain.start_row).was.called()
assert.spy(plain.label).was.called(7)
assert.spy(plain.spot).was.called(2)
assert.spy(plain.cell).was.called(369)
assert.spy(plain.end_row).was.called()
assert.spy(plain.end_table).was.called()
assert.spy(plain.end_document).was.called()
mock.revert(plain)
end)
end)
|