def __init__(self, value=0): if isinstance(value, str): self.roman = value self.value = roman_to_int(value) else: self.value = int(value) self.roman = int_to_roman(self.value)
def test_back_and_forth(self): """ Verify that an integer stay the same after the coversion to roman numeral and back to integer. """ for i in range(1, 5001): roman = int_to_roman(i) decimal = roman_to_int(roman) self.assertEqual(i, decimal)
def test_known_numerals(self): """ Verify the conversion of a list of known roman numerals. """ for i, numeral in enumerate(nums, 1): self.assertEqual(roman_to_int(numeral), i) self.assertEqual(int_to_roman(i), numeral)