Jump to content

Module:ConvertNumeric/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dcoetzee (talk | contribs) at 22:47, 24 February 2013 (Created page with '-- Unit tests for Module:ConvertNumeric. Click talk page to run tests. local p = {} local result_table = "{|\n! !! Text !! Expected !! Actual\n|-\n" local ...'). 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:ConvertNumeric]]. Click talk page to run tests.

local p = {}

local result_table = "{|\n! !! Text !! Expected !! Actual\n|-\n"
local num_failures = 0

function preprocess_equals(text, expected)
    local actual = frame:preprocess(text)
    if actual == expected then
        result_table = result_table .. '| {{Tick}} '
    else
        result_table = result_table .. '| {{Cross}} '
        num_failures = num_failures + 1
    end
    result_table = result_table .. ' || <nowiki>' .. text .. '</nowiki> || ' .. expected .. ' || ' .. actual .. "\n|-\n"
end

function test_numeral_to_english(frame)
    local prefix = '{{#invoke:ConvertNumeric | numeral_to_english |'
    preprocess_equals(prefix .. '-123456789.25 }}', 'negative one hundred twenty-three million four hundred fifty-six thousand seven hundred and eighty-nine point two five')
end

function p.run_tests(frame)
    test_numeral_to_english(frame)
    return (num_failures == 0 and "<font color=\"#008000\">'''All tests passed.'''</font>" or "<font color=\"#800000\">'''" .. num_failures .. " tests failed.'''</font>") .. "\n\n" .. result_table
end

return p