Module:Roman/testcases

local p = require('Module:UnitTests') local roman = require('Module:Roman/sandbox')

function p:test_1__number__toRoman__toArabic local nums = { 0, 5001, 7468, 10000, 12345, 13798, 21856, 123456, 1048576, 4999999999 } for i, num in ipairs(nums) do       self:equals('roman.toArabic(roman._Numeral(' .. num .. '))', roman.toArabic(roman._Numeral(num)), num) end end

function p:test_2_Roman__shorter --old template produced unnecessarily long Roman numerals for these values self:preprocess_equals_many('', {       { '9999', 'I̅X̅CMXCIX' },        { '14999', 'X̅I̅V̅CMXCIX' },        { '34850', 'X̅X̅X̅I̅V̅DCCCL' },    }) end

function p:test_3_Roman__misc__formatting self:preprocess_equals_many('', {       { '0', 'N' },        { ' 1', 'I' },        { '04', 'IV' },        { '0004', 'IV' },        { ' 04 ', 'IV' },        { '5987654321', '5987654321' },    }) end

function p:test_4_isRoman self:equals('roman.isRoman("")', roman.isRoman(""), false) self:equals('roman.isRoman("AbCd")', roman.isRoman("AbCd"), false) self:equals('roman.isRoman("第")', roman.isRoman("第"), false) self:equals('roman.isRoman("34")', roman.isRoman("34"), false) self:equals('roman.isRoman("I")', roman.isRoman("I"), true) self:equals('roman.isRoman("ⅩⅣ")', roman.isRoman("ⅩⅣ"), true) self:equals('roman.isRoman("V̅")', roman.isRoman("V̅"), true) end

function p:test_5_Roman__toArabic self:equals('roman.toArabic("")', roman.toArabic(""), nil) self:equals('roman.toArabic("AbCd")', roman.toArabic("AbCd"), nil) self:equals('roman.toArabic("第")', roman.toArabic("第"), nil) self:equals('roman.toArabic("34")', roman.toArabic("34"), 34) self:equals('roman.toArabic(" I ")', roman.toArabic("  I "), 1) self:equals('roman.toArabic("ⅩⅣ")', roman.toArabic("ⅩⅣ"), 14) self:equals('roman.toArabic(" V̅ ")', roman.toArabic("  V̅ "), 5000)

self:equals('roman.toArabic("I")', roman.toArabic("I"), 1) self:equals('roman.toArabic("II")', roman.toArabic("II"), 2) self:equals('roman.toArabic("IV")', roman.toArabic("IV"), 4) self:equals('roman.toArabic("XIV")', roman.toArabic("XIV"), 14) self:equals('roman.toArabic("XLIX")', roman.toArabic("XLIX"), 49) self:equals('roman.toArabic("L")', roman.toArabic("L"), 50) self:equals('roman.toArabic("LI")', roman.toArabic("LI"), 51) self:equals('roman.toArabic("CI")', roman.toArabic("CI"), 101) self:equals('roman.toArabic("CCIII")', roman.toArabic("CCIII"), 203) self:equals('roman.toArabic("DX")', roman.toArabic("DX"), 510) self:equals('roman.toArabic("CMXCIX")', roman.toArabic("CMXCIX"), 999) self:equals('roman.toArabic("M")', roman.toArabic("M"), 1000) self:equals('roman.toArabic("MXXIV")', roman.toArabic("MXXIV"), 1024) self:equals('roman.toArabic("MCMLXXIX")', roman.toArabic("MCMLXXIX"), 1979) self:equals('roman.toArabic("MM")', roman.toArabic("MM"), 2000) self:equals('roman.toArabic("MMXI")', roman.toArabic("MMXI"), 2011) self:equals('roman.toArabic("MMCMXCIX")', roman.toArabic("MMCMXCIX"), 2999) self:equals('roman.toArabic("MMM")', roman.toArabic("MMM"), 3000) self:equals('roman.toArabic("MMMI")', roman.toArabic("MMMI"), 3001) self:equals('roman.toArabic("MMMMCMLXXXVII")', roman.toArabic("MMMMCMLXXXVII"), 4987) self:equals('roman.toArabic("MMMMCMXCIX")', roman.toArabic("MMMMCMXCIX"), 4999) self:equals('roman.toArabic("V̅")', roman.toArabic("V̅"), 5000) end

return p