Modul:Age utilities/testtilfeller


--local ageUtil = require('Module:Age utilities/sandbox')
local ageUtil = require('Module:Age utilities')

local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

local ageInYearsAndDays = ageUtil.ageInYearsAndDays
local compareAges = ageUtil.compareAges
local equalAges = ageUtil.equalAges
local ageInYearsAndDaysFormat = ageUtil.ageInYearsAndDaysFormat

--------------------------------------------------------------------------------
-- Basic tests
--------------------------------------------------------------------------------

function suite:test_ageBothLeaps()
	self:assertDeepEquals({years = 12, days = 30}, ageInYearsAndDays(os.time({year = 2012, month = 3, day = 2}), os.time({year = 2000, month = 2, day = 1})))
end

function suite:test_ageOneLeap()
	self:assertDeepEquals({years = 13, days = 30}, ageInYearsAndDays(os.time({year = 2012, month = 3, day = 2}), os.time({year = 1999, month = 2, day = 1})))
end

function suite:test_ageNoneLeap()
	self:assertDeepEquals({years = 12, days = 29}, ageInYearsAndDays(os.time({year = 2011, month = 3, day = 2}), os.time({year = 1999, month = 2, day = 1})))
end

function suite:test_ageSomething()
	self:assertDeepEquals({years = 1984, days = 42}, ageInYearsAndDays(os.time({year = 2001, month = 5, day = 14}), os.time({year = 17, month = 4, day = 2})))
end

function suite:test_compareAgesLess1()
	self:assertEquals(true, 0 > compareAges({years = 99, days = 100}, {years = 100, days = 100}))
end

function suite:test_compareAgesLess2()
	self:assertEquals(true, 0 > compareAges({years = 100, days = 99}, {years = 100, days = 100}))
end

function suite:test_compareAgesGreater1()
	self:assertEquals(true, 0 < compareAges({years = 100, days = 100}, {years = 99, days = 100}))
end

function suite:test_compareAgesGreater2()
	self:assertEquals(true, 0 < compareAges({years = 100, days = 100}, {years = 100, days = 99}))
end

function suite:test_compareAgesEqual()
	self:assertEquals(true, 0 == compareAges({years = 100, days = 100}, {years = 100, days = 100}))
end

function suite:test_equalAges()
	self:assertEquals(true, equalAges({years = 1984, days = 42}, {years = 1984, days = 42}))
end

function suite:test_compareAgeOutputSeveralDays()
	self:assertSameResult('{{Tid i år og dager|1875|2|21|1997|8|4}}', ageInYearsAndDaysFormat(ageInYearsAndDays(os.time({year = 1997, month = 8, day = 4}), os.time({year = 1875, month = 2, day = 21}))))
end

function suite:test_compareAgeOutputOneDay()
	self:assertSameResult('{{Tid i år og dager|1879|10|15|1991|10|16}}', ageInYearsAndDaysFormat(ageInYearsAndDays(os.time({year = 1991, month = 10, day = 16}), os.time({year = 1879, month = 10, day = 15}))))
end

--[[
function suite:testNot4()
	self:assertEquals(false, isLeapYear(1999))
end

function suite:test4not100not400()
	self:assertEquals(true, isLeapYear(1984))
end

function suite:test100not400()
	self:assertEquals(false, isLeapYear(1000))
end

function suite:test400()
	self:assertEquals(true, isLeapYear(2000))
end
]]

return suite