Jump to content

Module:Math/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jarekt (talk | contribs) at 18:31, 3 December 2013 (Created page with '-- Unit tests for Module:Math. Click talk page to run tests. local p = require('Module:UnitTests') function p:test_random() self:preprocess_equals_ma...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
-- Unit tests for [[Module:Math]]. Click talk page to run tests.
 
local p = require('Module:UnitTests')
 
function p:test_random()
    self:preprocess_equals_many ('{{#Invoke:math|random', '}}', {
    {'', '0.00047147460303804'},
    {'|10','8'},
    {'|1|2','2'},
    })
end
 
function p:test_max()
    self:preprocess_equals_many ('{{#Invoke:math|max|', '}}', {
    {'',''},
    {'5|6|9', '9'},
    {'-5|-6|-9', '-5'},
    })
end
 
function p:test_average()
    self:preprocess_equals_many ('{{#Invoke:math|average|', '}}', {
    {'5|6|7', '6'},
    {'-7', '-7'},
    {'10000000001|10000000002|10000000003', '10000000002'},
    })
end
 
function p:test_min()
    self:preprocess_equals_many ('{{#Invoke:math|min|', '}}', {
    {'',''},
    {'1|2|3','1'},
    {'-1|-2|-3','-3'},
    })
end
 
function p:test_order()
    self:preprocess_equals_many ('{{#Invoke:math|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 p:test_precison()
    self:preprocess_equals_many ('{{#Invoke:math|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 p:test_round()
    self:preprocess_equals_many ('{{#Invoke:math|round|', '}}', {
{'1.99999', '2'},
{'1.99999|0', '2'},
{'1.94|1', '1.9'},
{'15|-1', '20'},
{'value = 2.99999|precision = 2', '3'},
})
end
 
function p:test_precison_format()
    self:preprocess_equals('{{#Invoke:math|precision_format|10|2}}', '10.00')
end
 
return p