From 587cad6d396b0a507f87e83369b156b7dad20635 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 8 Feb 2024 23:41:36 +0100 Subject: Generate rolling chart with activity --- spec/activity_spec.lua | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'spec/activity_spec.lua') diff --git a/spec/activity_spec.lua b/spec/activity_spec.lua index 581b0ba..38338e8 100644 --- a/spec/activity_spec.lua +++ b/spec/activity_spec.lua @@ -43,21 +43,26 @@ Fri 0000000000000000000000000000000000000000000000000000_ ]] -describe("Generator", function() - describe("shall generate correct table for year", function() - local function lookup (year, day) return 0 end +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, activity.generate_table(2024, lookup, plain)) + assert.are.equal(Y2024, activity.generate_table(2024, always_zero, plain)) end) it("2023", function() - assert.are.equal(Y2023, activity.generate_table(2023, lookup, plain)) + assert.are.equal(Y2023, activity.generate_table(2023, always_zero, plain)) end) it("2020", function() - assert.are.equal(Y2020, activity.generate_table(2020, lookup, plain)) + assert.are.equal(Y2020, activity.generate_table(2020, always_zero, plain)) end) + end) describe("shall put activity into cells for", function() @@ -76,9 +81,28 @@ describe("Generator", function() assert.are.equal(Y2024:gsub("0", "1"), activity.generate_table(2024, lookup, plain)) end) end) +end) + + +describe("Rolling chart generator", function() + it("shall generate empty table", function() + local date = os.date("*t", os.time{year=2024, month=2, day=8}) + assert.are.equal(ROLL, activity.generate_table("rolling", always_zero, plain, date)) + end) - it("shall support generating rolling table", function() + it("shall put activity into cells", function() local date = os.date("*t", os.time{year=2024, month=2, day=8}) - assert.are.equal(ROLL, activity.generate_table("rolling", lookup, plain, date)) + + 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"), activity.generate_table("rolling", lookup, plain, date)) end) end) -- cgit v1.1