Module:ConvertNumeric/testcases
- පහත දැක්වෙන උපදෙස්, Module:ConvertNumeric/testcases/documentation හි පිහිටා ඇත. Module:ConvertNumeric/testcases/documentation]]. [සංස්කරණය]
- ප්රයෝජනවත් සබැඳි: root page • root page’s subpages • සබැඳි • transclusions • tested module • sandbox
All tests passed. (refresh)
Text | Expected | Actual | Differs at | |
---|---|---|---|---|
{{#invoke:ConvertNumeric|decToHex|10 20 40 1024 78912345|minlength=4}} | 000A 0014 0028 0400 4B41B59 | 000A 0014 0028 0400 4B41B59 |
Text | Expected | Actual | Differs at | |
---|---|---|---|---|
{{#invoke:ConvertNumeric | numeral_to_english |0}} | zero | zero | ||
{{#invoke:ConvertNumeric | numeral_to_english |1}} | one | one | ||
{{#invoke:ConvertNumeric | numeral_to_english | 1 }} | one | one | ||
{{#invoke:ConvertNumeric | numeral_to_english |1 | case=u}} | One | One | ||
{{#invoke:ConvertNumeric | numeral_to_english |1 | case=U}} | One | One | ||
{{#invoke:ConvertNumeric | numeral_to_english |-1}} | negative one | negative one | ||
{{#invoke:ConvertNumeric | numeral_to_english |-1 | negative=minus}} | minus one | minus one | ||
{{#invoke:ConvertNumeric | numeral_to_english |70}} | seventy | seventy | ||
{{#invoke:ConvertNumeric | numeral_to_english |42}} | forty-two | forty-two | ||
{{#invoke:ConvertNumeric | numeral_to_english |123}} | one hundred and twenty-three | one hundred and twenty-three | ||
{{#invoke:ConvertNumeric | numeral_to_english |123 | sp=us}} | one hundred twenty-three | one hundred twenty-three | ||
{{#invoke:ConvertNumeric | numeral_to_english |123 | adj=on}} | one-hundred-and-twenty-three | one-hundred-and-twenty-three | ||
{{#invoke:ConvertNumeric | numeral_to_english |1050}} | one thousand and fifty | one thousand and fifty | ||
{{#invoke:ConvertNumeric | numeral_to_english |1050 | sp=us}} | one thousand fifty | one thousand fifty | ||
{{#invoke:ConvertNumeric | numeral_to_english |0.25}} | zero point two five | zero point two five | ||
{{#invoke:ConvertNumeric | numeral_to_english |.25}} | zero point two five | zero point two five | ||
{{#invoke:ConvertNumeric | numeral_to_english |0 | ord=on}} | zeroth | zeroth | ||
{{#invoke:ConvertNumeric | numeral_to_english |33 | ord=on}} | thirty-third | thirty-third | ||
{{#invoke:ConvertNumeric | numeral_to_english |40 | ord=on}} | fortieth | fortieth | ||
{{#invoke:ConvertNumeric | numeral_to_english |5000000000 | ord=on}} | five billionth | five billionth | ||
{{#invoke:ConvertNumeric | numeral_to_english |0 | pl=on}} | zeros | zeros | ||
{{#invoke:ConvertNumeric | numeral_to_english |76 | pl=on}} | seventy-sixes | seventy-sixes | ||
{{#invoke:ConvertNumeric | numeral_to_english |1000000000000000000000000000001}} | one nonillion and one | one nonillion and one | ||
{{#invoke:ConvertNumeric | numeral_to_english |1.23E3}} | one thousand two hundred and thirty | one thousand two hundred and thirty | ||
{{#invoke:ConvertNumeric | numeral_to_english |123E-4}} | zero point zero one two three | zero point zero one two three | ||
{{#invoke:ConvertNumeric | numeral_to_english |1001001001001000 | lk=on}} | one quadrillion one trillion one billion one million one thousand | one quadrillion one trillion one billion one million one thousand | ||
{{#invoke:ConvertNumeric | numeral_to_english |1001001001001000 | lk=billion,quadrillion}} | one quadrillion one trillion one billion one million one thousand | one quadrillion one trillion one billion one million one thousand | ||
{{#invoke:ConvertNumeric | numeral_to_english |5E30}} | five nonillion | five nonillion | ||
{{#invoke:ConvertNumeric | numeral_to_english |-123456789.25}} | negative one hundred twenty-three million four hundred fifty-six thousand seven hundred and eighty-nine point two five | negative one hundred twenty-three million four hundred fifty-six thousand seven hundred and eighty-nine point two five | ||
{{#invoke:ConvertNumeric | numeral_to_english |0 | zero=foo}} | foo | foo | ||
{{#invoke:ConvertNumeric | numeral_to_english |0 | ord=on | zero=none}} | none | none | ||
{{#invoke:ConvertNumeric | numeral_to_english |1 | numerator=2 | denominator=3}} | one and two-thirds | one and two-thirds | ||
{{#invoke:ConvertNumeric | numeral_to_english || numerator=2 | denominator=3}} | two-thirds | two-thirds | ||
{{#invoke:ConvertNumeric | numeral_to_english |1 | denominator=2}} | one and a half | one and a half | ||
{{#invoke:ConvertNumeric | numeral_to_english |1 | numerator=3 | denominator=2}} | one and three-halves | one and three-halves | ||
{{#invoke:ConvertNumeric | numeral_to_english |1 | numerator=1 | denominator=4}} | one and a quarter | one and a quarter | ||
{{#invoke:ConvertNumeric | numeral_to_english |1 | numerator=1 | denominator=4 | sp=us}} | one and a fourth | one and a fourth | ||
{{#invoke:ConvertNumeric | numeral_to_english |1 | numerator=1 | denominator=4 | one=one}} | one and one-quarter | one and one-quarter | ||
{{#invoke:ConvertNumeric | numeral_to_english |1 | numerator=1 | denominator=4 | sp=us | one=one}} | one and one-fourth | one and one-fourth | ||
{{#invoke:ConvertNumeric | numeral_to_english |9 | numerator=3 | denominator=4}} | nine and three-quarters | nine and three-quarters | ||
{{#invoke:ConvertNumeric | numeral_to_english |9 | numerator=3 | denominator=4 | sp=us}} | nine and three-fourths | nine and three-fourths | ||
{{#invoke:ConvertNumeric | numeral_to_english |23 | numerator=12 | denominator=16}} | twenty-three and twelve-sixteenths | twenty-three and twelve-sixteenths |
Text | Expected | Actual | Differs at | |
---|---|---|---|---|
{{#invoke:ConvertNumeric | numeral_to_english |}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |a}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |.}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |e}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |E}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |E1}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |.E1}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |+}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |-}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |123a}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |a123}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |0.1a}} | Invalid decimal numeral | Invalid decimal numeral | ||
{{#invoke:ConvertNumeric | numeral_to_english |-a123}} | Invalid decimal numeral | Invalid decimal numeral |
Text | Expected | Actual | Differs at | |
---|---|---|---|---|
{{#invoke:ConvertNumeric | numeral_to_english |1 | round=on}} | one | one | ||
{{#invoke:ConvertNumeric | numeral_to_english |37 | round=on}} | thirty-seven | thirty-seven | ||
{{#invoke:ConvertNumeric | numeral_to_english |190 | round=on}} | two hundred | two hundred | ||
{{#invoke:ConvertNumeric | numeral_to_english |110 | round=up}} | two hundred | two hundred | ||
{{#invoke:ConvertNumeric | numeral_to_english |190 | round=down}} | one hundred | one hundred | ||
{{#invoke:ConvertNumeric | numeral_to_english |87654321 | round=on}} | ninety million | ninety million | ||
{{#invoke:ConvertNumeric | numeral_to_english |12345678 | round=on}} | twelve million | twelve million | ||
{{#invoke:ConvertNumeric | numeral_to_english |-190 | round=on}} | negative two hundred | negative two hundred | ||
{{#invoke:ConvertNumeric | numeral_to_english |-190 | round=up}} | negative one hundred | negative one hundred | ||
{{#invoke:ConvertNumeric | numeral_to_english |-110 | round=down}} | negative two hundred | negative two hundred | ||
{{#invoke:ConvertNumeric | numeral_to_english |0.25 | round=on}} | zero | zero | ||
{{#invoke:ConvertNumeric | numeral_to_english |0.5 | round=on}} | one | one | ||
{{#invoke:ConvertNumeric | numeral_to_english |-0.25 | round=on}} | zero | zero | ||
{{#invoke:ConvertNumeric | numeral_to_english |-0.5 | round=on}} | negative one | negative one | ||
{{#invoke:ConvertNumeric | numeral_to_english |0.01 | round=up}} | one | one | ||
{{#invoke:ConvertNumeric | numeral_to_english |0.99 | round=down}} | zero | zero | ||
{{#invoke:ConvertNumeric | numeral_to_english |-0.01 | round=down}} | negative one | negative one | ||
{{#invoke:ConvertNumeric | numeral_to_english |-0.99 | round=up}} | zero | zero |
-- Unit tests for [[Module:ConvertNumeric]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local frame = mw.getCurrentFrame()
local function get_error_text(wikitext)
local message = frame:preprocess(wikitext):match('<strong class="error"><[^>]+>(.-)<[^>]+></strong>')
message = message:match('at line %d+: (.+)%.$') or message
return message
end
function p:test_numeral_to_english()
self:preprocess_equals_many('{{#invoke:ConvertNumeric | numeral_to_english |', '}}', {
{'0', 'zero'},
{'1', 'one'},
{' 1 ', 'one'}, -- test whitespace around number
{'1 | case=u', 'One'},
{'1 | case=U', 'One'},
{'-1', 'negative one'},
{'-1 | negative=minus', 'minus one'},
{'70', 'seventy'},
{'42', 'forty-two'},
{'123', 'one hundred and twenty-three'},
{'123 | sp=us', 'one hundred twenty-three'},
{'123 | adj=on', 'one-hundred-and-twenty-three'},
{'1050', 'one thousand and fifty'},
{'1050 | sp=us', 'one thousand fifty'},
{'0.25', 'zero point two five'},
{'.25', 'zero point two five'},
{'0 | ord=on', 'zeroth'},
{'33 | ord=on', 'thirty-third'},
{'40 | ord=on', 'fortieth'},
{'5000000000 | ord=on', 'five billionth'},
{'0 | pl=on', 'zeros'},
{'76 | pl=on', 'seventy-sixes'},
{'1000000000000000000000000000001', 'one nonillion and one'},
{'1.23E3', 'one thousand two hundred and thirty'},
{'123E-4', 'zero point zero one two three'},
{'1001001001001000 | lk=on', 'one [[Orders_of_magnitude_(numbers)#1015|quadrillion]] one [[Orders_of_magnitude_(numbers)#1012|trillion]] one [[Orders_of_magnitude_(numbers)#109|billion]] one million one thousand'},
{'1001001001001000 | lk=billion,quadrillion', 'one [[Orders_of_magnitude_(numbers)#1015|quadrillion]] one trillion one [[Orders_of_magnitude_(numbers)#109|billion]] one million one thousand'},
{'5E30', 'five nonillion'},
{'-123456789.25', 'negative one hundred twenty-three million four hundred fifty-six thousand seven hundred and eighty-nine point two five'},
{'0 | zero=foo', 'foo'},
{'0 | ord=on | zero=none', 'none'},
{'1 | numerator=2 | denominator=3', 'one and two-thirds'},
{'| numerator=2 | denominator=3', 'two-thirds'},
{'1 | denominator=2', 'one and a half'},
{'1 | numerator=3 | denominator=2', 'one and three-halves'},
{'1 | numerator=1 | denominator=4', 'one and a quarter'},
{'1 | numerator=1 | denominator=4 | sp=us', 'one and a fourth'},
{'1 | numerator=1 | denominator=4 | one=one', 'one and one-quarter'},
{'1 | numerator=1 | denominator=4 | sp=us | one=one', 'one and one-fourth'},
{'9 | numerator=3 | denominator=4', 'nine and three-quarters'},
{'9 | numerator=3 | denominator=4 | sp=us', 'nine and three-fourths'},
{'23 | numerator=12 | denominator=16', 'twenty-three and twelve-sixteenths'},
})
end
function p:test_numeral_to_english_error()
local cases = {'', 'a', '.', 'e', 'E', 'E1', '.E1', '+', '-', '123a', 'a123', '0.1a', '-a123' }
local nowiki = mw.text.nowiki
for _, case in ipairs(cases) do
local wikitext = '{{#invoke:ConvertNumeric | numeral_to_english |' .. case .. '}}'
self:equals(nowiki(wikitext), get_error_text(wikitext), 'Invalid decimal numeral')
end
end
function p:test_numeral_to_english_round()
self:preprocess_equals_many('{{#invoke:ConvertNumeric | numeral_to_english |', '}}', {
{'1 | round=on', 'one'},
{'37 | round=on', 'thirty-seven'},
{'190 | round=on', 'two hundred'},
{'110 | round=up', 'two hundred'},
{'190 | round=down', 'one hundred'},
{'87654321 | round=on', 'ninety million'},
{'12345678 | round=on', 'twelve million'},
{'-190 | round=on', 'negative two hundred'},
{'-190 | round=up', 'negative one hundred'},
{'-110 | round=down', 'negative two hundred'},
{'0.25 | round=on', 'zero'},
{'0.5 | round=on', 'one'},
{'-0.25 | round=on', 'zero'},
{'-0.5 | round=on', 'negative one'},
{'0.01 | round=up', 'one'},
{'0.99 | round=down', 'zero'},
{'-0.01 | round=down', 'negative one'},
{'-0.99 | round=up', 'zero'},
})
end
function p:test_decToHex()
self:preprocess_equals(
'{{#invoke:ConvertNumeric|decToHex|10 20 40 1024 78912345|minlength=4}}',
'000A 0014 0028 0400 4B41B59'
)
end
return p