This documentation is transcluded from Module:Commodity/testcases/doc. Changes can be proposed in the talk page.
Function list |
---|
L 9 — suite:testFormatOffset L 15 — suite:testFormatOffsetSpan L 23 — suite:testCalcPriceInt L 29 — suite:testCalcPriceFloat L 39 — suite:testCalcPricePPInt L 48 — suite:testCalcPricePPFloat |
Unit tests | |||
---|---|---|---|
Name | Expected | Actual | |
👌 | testCalcPriceFloat | ||
👌 | testCalcPriceInt | ||
👌 | testCalcPricePPFloat | ||
👌 | testCalcPricePPInt | ||
👌 | testFormatOffset | ||
👌 | testFormatOffsetSpan |
-- Unit tests for [[Module:Commodity]]
local module = require('Module:Commodity')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
--[[
module.formatOffset tests
]]--
function suite:testFormatOffset()
self:assertEquals('0%', module.formatOffset( 0 ))
self:assertEquals('0%', module.formatOffset( '0' ))
self:assertEquals('0%', module.formatOffset( nil ))
end
function suite:testFormatOffsetSpan()
self:assertEquals('<span title="10%">10%</span>', module.formatOffset( 10 ))
end
--[[
module.calcPrice tests
]]--
function suite:testCalcPriceInt()
self:assertEquals("100", module.calcPrice( 100, 0 ))
self:assertEquals("9", module.calcPrice( 100, -90 ))
self:assertEquals("190", module.calcPrice( 100, 90 ))
end
function suite:testCalcPriceFloat()
self:assertEquals("1,010", module.calcPrice( 1000, 1.1 ))
self:assertEquals("989", module.calcPrice( 1000, -1.1 ))
end
--[[
module.calcPricePP tests
]]--
function suite:testCalcPricePPInt()
-- 10 - 10%
self:assertEquals(9, module.calcPricePP( 10, 10 ))
-- 10 + 10%
self:assertEquals(11, module.calcPricePP( 10, 10, true ))
self:assertEquals(1100, module.calcPricePP( 1000, 10, true ))
end
function suite:testCalcPricePPFloat()
self:assertEquals(866.125, module.calcPricePP( 1025, 15.5, false, 3 ))
end
return suite