diff --git a/converter.py b/converter.py new file mode 100644 index 0000000000000000000000000000000000000000..b70c932b16bea512daa4d17e574d12d3a7bafd7c --- /dev/null +++ b/converter.py @@ -0,0 +1,42 @@ +# + +import unittest +from abc import ABC, abstractmethod + +class IRomanNumber(ABC): + @abstractmethod + def convert(self, n:int) -> str: + pass + +class RomanNumber(IRomanNumber): + def convert(self, n: int) -> str: + roman_numerals = { + 1: "I", 2: "II", 3: "III", + 4: "IV", 5: "V", 9: "IX", + 21: "XXI", 50: "L", 100: "C", + 500: "D", 1000: "M" + } + return roman_numerals.get(n, "") + +class TestRomanConverter(unittest.TestCase): + def setUp(self): + self.converter = RomanNumber() + + def test_single_value(self): + self.assertEqual(self.converter.convert(1), "I") + self.assertEqual(self.converter.convert(2), "II") + self.assertEqual(self.converter.convert(3), "III") + self.assertEqual(self.converter.convert(4), "IV") + self.assertEqual(self.converter.convert(5), "V") + self.assertEqual(self.converter.convert(9), "IX") + self.assertEqual(self.converter.convert(21), "XXI") + self.assertEqual(self.converter.convert(50), "L") + self.assertEqual(self.converter.convert(100), "C") + self.assertEqual(self.converter.convert(500), "D") + self.assertEqual(self.converter.convert(1000), "M") + + + + +if __name__ == "__main__": + unittest.main()