From 9b1f5d2b5554c0ff9f355866d4669b3ffcaa3686 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 9 Feb 2024 21:56:33 +0100 Subject: Moved the standalone activity.lua into activity.generators --- spec/activity_spec.lua | 108 ----------------------------------------------- spec/generators_spec.lua | 108 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 108 deletions(-) delete mode 100644 spec/activity_spec.lua create mode 100644 spec/generators_spec.lua (limited to 'spec') diff --git a/spec/activity_spec.lua b/spec/activity_spec.lua deleted file mode 100644 index 38338e8..0000000 --- a/spec/activity_spec.lua +++ /dev/null @@ -1,108 +0,0 @@ -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_ -]] - -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, activity.generate_table(2024, always_zero, plain)) - end) - - it("2023", function() - assert.are.equal(Y2023, activity.generate_table(2023, always_zero, plain)) - end) - - it("2020", function() - assert.are.equal(Y2020, activity.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"), 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) - - -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 put activity into cells", function() - local date = os.date("*t", os.time{year=2024, month=2, day=8}) - - 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) diff --git a/spec/generators_spec.lua b/spec/generators_spec.lua new file mode 100644 index 0000000..a6c1e9a --- /dev/null +++ b/spec/generators_spec.lua @@ -0,0 +1,108 @@ +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) +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, generators.generate_table("rolling", always_zero, plain, date)) + end) + + it("shall put activity into cells", function() + local date = os.date("*t", os.time{year=2024, month=2, day=8}) + + 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) +end) -- cgit v1.1