Module:roman numerals/testcases

Definition from Wiktionary, the free dictionary
Jump to navigation Jump to search

All tests passed. (refresh)

Text Expected Actual
test_arabic_to_roman:
Passed 1 I I
Passed 2 II II
Passed 3 III III
Passed 4 IV IV
Passed 5 V V
Passed 6 VI VI
Passed 7 VII VII
Passed 8 VIII VIII
Passed 9 IX IX
Passed 10 X X
Passed 944 CMXLIV CMXLIV
Passed 2848 MMDCCCXLVIII MMDCCCXLVIII
Passed 3999 MMMCMXCIX MMMCMXCIX
Text Expected Actual
test_roman_to_arabic:
Passed I 1 1
Passed II 2 2
Passed III 3 3
Passed IV 4 4
Passed V 5 5
Passed VI 6 6
Passed VII 7 7
Passed VIII 8 8
Passed IX 9 9
Passed X 10 10
Passed MCCXLI 1241 1241
Passed CMXCIX 999 999
Passed MMMCMXCIX 3999 3999

local tests = require('Module:UnitTests')
local m_roman = require('Module:roman_numerals')

function tests:check_roman_to_arabic(roman, arabic)
	self:equals(
		roman,
		m_roman.roman_to_arabic(roman), arabic
	)
end

function tests:check_arabic_to_roman(arabic, roman)
	self:equals(
		arabic,
		m_roman.arabic_to_roman(arabic), roman
	)
end

function tests:test_arabic_to_roman()
	self:check_arabic_to_roman(1, "I")
	self:check_arabic_to_roman(2, "II")
	self:check_arabic_to_roman(3, "III")
	self:check_arabic_to_roman(4, "IV")
	self:check_arabic_to_roman(5, "V")
	self:check_arabic_to_roman(6, "VI")
	self:check_arabic_to_roman(7, "VII")
	self:check_arabic_to_roman(8, "VIII")
	self:check_arabic_to_roman(9, "IX")
	self:check_arabic_to_roman(10, "X")
	self:check_arabic_to_roman(944, "CMXLIV")
	self:check_arabic_to_roman(2848, "MMDCCCXLVIII")
	self:check_arabic_to_roman(3999, "MMMCMXCIX")
	
end

function tests:test_roman_to_arabic()
	self:check_roman_to_arabic("I", 1)
	self:check_roman_to_arabic("II", 2)
	self:check_roman_to_arabic("III", 3)
	self:check_roman_to_arabic("IV", 4)
	self:check_roman_to_arabic("V", 5)
	self:check_roman_to_arabic("VI", 6)
	self:check_roman_to_arabic("VII", 7)
	self:check_roman_to_arabic("VIII", 8)
	self:check_roman_to_arabic("IX", 9)
	self:check_roman_to_arabic("X", 10)
	self:check_roman_to_arabic("MCCXLI", 1241)
	self:check_roman_to_arabic("CMXCIX", 999)
	self:check_roman_to_arabic("MMMCMXCIX", 3999)
end

return tests