Jump to content

Module:Math/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 10:47, 6 December 2013 (test using Module:ScribuntoUnit for test cases). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module:Math]]. Click talk page to run tests.

local mm = require('Module:Math/sandbox') -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

local function invokeMath(funcName, argString)
	return '{{#invoke:math/sandbox|' .. funcName .. argString or '' .. '}}'
end
 
--[[
function suite:test_random()
    self:assertResultEquals ('{{#Invoke:math/sandbox|random', '}}', {
    {'', '0.00047147460303804'},
    {'|10','8'},
    {'|1|2','2'},
    })
end
]]
 
function suite:test_max()
	local tests = {
		{'', ''},
		{'', '|'},
		{'9', '|5|6|9'},
		{'-5', '|-5|-6|-9'},
	}
	for i, t in ipairs(tests) do
		self:assertResultEquals(t[1], invokeMath('max', t[2]))
	end
end
 
--[[
function suite:test_average()
    self:assertResultEquals ('{{#Invoke:math/sandbox|average|', '}}', {
    {'5|6|7', '6'},
    {'-7', '-7'},
    {'10000000001|10000000002|10000000003', '10000000002'},
    })
end
 
function suite:test_min()
    self:assertResultEquals ('{{#Invoke:math/sandbox|min|', '}}', {
    {'',''},
    {'1|2|3','1'},
    {'-1|-2|-3','-3'},
    })
end
 
function suite:test_order()
    self:assertResultEquals ('{{#Invoke:math/sandbox|order|', '}}', {
    {'2','0'},
    {'20','1'},
    {'200','2'},
    {'x = 5','0'},
    {'string','<strong class="error">Formatting error: Order of magnitude input appears non-numeric</strong>'},
})
end
 
function suite:test_precison()
    self:assertResultEquals ('{{#Invoke:math/sandbox|precision|', '}}', {
{'1.9856', '4'},
{'1.1', '1'},
{'1.9999999999', '10'},
{'x = 1.9888', '4'},
{'letra', '<strong class="error">Formatting error: Precision input appears non-numeric</strong>'},
})
end
 
function suite:test_round()
    self:assertResultEquals ('{{#Invoke:math/sandbox|round|', '}}', {
{'1.99999', '2'},
{'1.99999|0', '2'},
{'1.94|1', '1.9'},
{'15|-1', '20'},
{'value = 2.99999|precision = 2', '3'},
})
end
 
function suite:test_precison_format()
    self:preprocess_equals('{{#Invoke:math/sandbox|precision_format|10|2}}', '10.00')
end
]]
 
return suite