Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Common/testcases

From the Star Citizen Wiki, the fidelity™ encyclopedia
Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:Common/testcases/doc. Changes can be proposed in the talk page.
Function list
L 9 — suite:testRemoveTypeSuffix
L 15 — suite:testRemoveTypeSuffixNoMatch
L 23 — suite:testToNumberNum
L 32 — suite:testToNumberString
L 39 — suite:testToNumberStringFail
L 48 — suite:testFormatNum
L 58 — suite:testFormatNumberString
L 65 — suite:testFormatNumberStringFail
👌 All tests passed.
Unit tests
Name Expected Actual
👌 testFormatNum
👌 testFormatNumberString
👌 testFormatNumberStringFail
👌 testRemoveTypeSuffix
👌 testRemoveTypeSuffixNoMatch
👌 testToNumberNum
👌 testToNumberString
👌 testToNumberStringFail

-- Unit tests for [[Module:Common]]. Click talk page to run tests.
local common = require('Module:Common')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

--[[
    common.removeTypeSuffix tests
]]--
function suite:testRemoveTypeSuffix()
    self:assertEquals('Ship', common.removeTypeSuffix( 'Ship (ship)', 'ship' ))
    self:assertEquals('Test', common.removeTypeSuffix( 'Test (test)', 'test' ))
    self:assertEquals('Sample page', common.removeTypeSuffix( 'Sample page (sample)', 'sample' ))
end

function suite:testRemoveTypeSuffixNoMatch()
    self:assertEquals('Page name', common.removeTypeSuffix( 'Page name', 'ship' ))
end


--[[
    common.toNumber tests
]]--
function suite:testToNumberNum()
    self:assertEquals(10, common.toNumber(10))
    self:assertEquals(15, common.toNumber(15))
    self:assertEquals(0, common.toNumber(0))
    self:assertEquals(-123123123, common.toNumber(-123123123))
    self:assertEquals(0.001, common.toNumber(0.001))
    self:assertEquals(202.5, common.toNumber(202.5))
end

function suite:testToNumberString()
    self:assertEquals(125, common.toNumber("125"))
    self:assertEquals(12.5, common.toNumber("12.5"))
    self:assertEquals(12.5, common.toNumber("12.5"))
    self:assertEquals(202.5, common.toNumber("202.5"))
end

function suite:testToNumberStringFail()
    self:assertEquals(0, common.toNumber("NotANumber", 0))
    self:assertEquals(nil, common.toNumber("NotANumber"))
end


--[[
    common.formatNum tests
]]--
function suite:testFormatNum()
    self:assertEquals("10", common.formatNum(10))
    self:assertEquals("15", common.formatNum(15))
    self:assertEquals("0", common.formatNum(0))
    self:assertEquals("-123,123,123", common.formatNum(-123123123))
    self:assertEquals("0.001", common.formatNum(0.001))
    self:assertEquals("0.001", common.formatNum(.001))
    self:assertEquals("202.5", common.formatNum(202.5))
end

function suite:testFormatNumberString()
    self:assertEquals("125", common.formatNum("125"))
    self:assertEquals("12.5", common.formatNum("12.5"))
    self:assertEquals("12.5", common.formatNum("12,5"))
    self:assertEquals("202.5", common.formatNum("202.5"))
end

function suite:testFormatNumberStringFail()
    self:assertEquals(false, common.formatNum("NotANumber"))
end

return suite