summaryrefslogtreecommitdiff
path: root/spec/activity_spec.lua
blob: 197b57fd33761b97dba04cd8e786015b3302dff8 (plain)
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
local activity = require "activity"
local dates = require "activity.dates"
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_
]]


describe("Generator", function()
	describe("shall generate correct table for year", function()
		local function lookup (year, day) return 0 end

		it("2024", function()
			assert.are.equal(Y2024, activity.generate_table(2024, lookup, plain))
		end)

		it("2023", function()
			assert.are.equal(Y2023, activity.generate_table(2023, lookup, plain))
		end)

		it("2020", function()
			assert.are.equal(Y2020, activity.generate_table(2020, lookup, 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"), activity.generate_table(2023, lookup, plain))
		end)

		it("leap years", function()
			assert.are.equal(Y2024:gsub("0", "1"), activity.generate_table(2024, lookup, plain))
		end)
	end)
end)