Module:roman numerals/testcases

From Wiktionary, the free dictionary
Jump to navigation Jump to search

All tests passed. (refresh)

TextExpectedActual
test_arabic_to_roman:
Passed1II
Passed2IIII
Passed3IIIIII
Passed4IVIV
Passed5VV
Passed6VIVI
Passed7VIIVII
Passed8VIIIVIII
Passed9IXIX
Passed10XX
Passed944CMXLIVCMXLIV
Passed2848MMDCCCXLVIIIMMDCCCXLVIII
Passed3999MMMCMXCIXMMMCMXCIX
TextExpectedActual
test_roman_to_arabic:
PassedI11
PassedII22
PassedIII33
PassedIV44
PassedV55
PassedVI66
PassedVII77
PassedVIII88
PassedIX99
PassedX1010
PassedMCCXLI12411241
PassedCMXCIX999999
PassedMMMCMXCIX39993999

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