Difference between revisions of "Module:Math/testcases"

From blackwiki
Jump to navigation Jump to search
blackwiki>Mr. Stradivarius
(test module sandbox)
blackwiki>Mr. Stradivarius
(test using Module:ScribuntoUnit for test cases)
Line 1: Line 1:
 
-- Unit tests for [[Module:Math]]. Click talk page to run tests.
 
-- 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
 
   
 
   
local p = require('Module:UnitTests')
+
--[[
+
function suite:test_random()
function p:test_random()
+
     self:assertResultEquals ('{{#Invoke:math/sandbox|random', '}}', {
     self:preprocess_equals_many ('{{#Invoke:math/sandbox|random', '}}', {
 
 
     {'', '0.00047147460303804'},
 
     {'', '0.00047147460303804'},
 
     {'|10','8'},
 
     {'|10','8'},
Line 10: Line 17:
 
     })
 
     })
 
end
 
end
 +
]]
 
   
 
   
function p:test_max()
+
function suite:test_max()
    self:preprocess_equals_many ('{{#Invoke:math/sandbox|max|', '}}', {
+
local tests = {
    {'',''},
+
{'', ''},
    {'5|6|9', '9'},
+
{'', '|'},
    {'-5|-6|-9', '-5'},
+
{'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
 
end
 
   
 
   
function p:test_average()
+
--[[
     self:preprocess_equals_many ('{{#Invoke:math/sandbox|average|', '}}', {
+
function suite:test_average()
 +
     self:assertResultEquals ('{{#Invoke:math/sandbox|average|', '}}', {
 
     {'5|6|7', '6'},
 
     {'5|6|7', '6'},
 
     {'-7', '-7'},
 
     {'-7', '-7'},
Line 27: Line 40:
 
end
 
end
 
   
 
   
function p:test_min()
+
function suite:test_min()
     self:preprocess_equals_many ('{{#Invoke:math/sandbox|min|', '}}', {
+
     self:assertResultEquals ('{{#Invoke:math/sandbox|min|', '}}', {
 
     {'',''},
 
     {'',''},
 
     {'1|2|3','1'},
 
     {'1|2|3','1'},
Line 35: Line 48:
 
end
 
end
 
   
 
   
function p:test_order()
+
function suite:test_order()
     self:preprocess_equals_many ('{{#Invoke:math/sandbox|order|', '}}', {
+
     self:assertResultEquals ('{{#Invoke:math/sandbox|order|', '}}', {
 
     {'2','0'},
 
     {'2','0'},
 
     {'20','1'},
 
     {'20','1'},
Line 45: Line 58:
 
end
 
end
 
   
 
   
function p:test_precison()
+
function suite:test_precison()
     self:preprocess_equals_many ('{{#Invoke:math/sandbox|precision|', '}}', {
+
     self:assertResultEquals ('{{#Invoke:math/sandbox|precision|', '}}', {
 
{'1.9856', '4'},
 
{'1.9856', '4'},
 
{'1.1', '1'},
 
{'1.1', '1'},
Line 55: Line 68:
 
end
 
end
 
   
 
   
function p:test_round()
+
function suite:test_round()
     self:preprocess_equals_many ('{{#Invoke:math/sandbox|round|', '}}', {
+
     self:assertResultEquals ('{{#Invoke:math/sandbox|round|', '}}', {
 
{'1.99999', '2'},
 
{'1.99999', '2'},
 
{'1.99999|0', '2'},
 
{'1.99999|0', '2'},
Line 65: Line 78:
 
end
 
end
 
   
 
   
function p:test_precison_format()
+
function suite:test_precison_format()
 
     self:preprocess_equals('{{#Invoke:math/sandbox|precision_format|10|2}}', '10.00')
 
     self:preprocess_equals('{{#Invoke:math/sandbox|precision_format|10|2}}', '10.00')
 
end
 
end
 +
]]
 
   
 
   
return p
+
return suite

Revision as of 10:47, 6 December 2013

Documentation for this module may be created at Module:Math/testcases/doc

-- 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