Ejemplo n.º 1
0
 def test_Calculate_Solution(self):
     sol = Solution()
     self.assertEqual('III', sol.intToRoman(3))
     self.assertEqual('IV', sol.intToRoman(4))
     self.assertEqual('IX', sol.intToRoman(9))
     self.assertEqual('LVIII', sol.intToRoman(58))
     self.assertEqual('MCMXCIV', sol.intToRoman(1994))
Ejemplo n.º 2
0
class IntegerToRomanTest(unittest.TestCase):
    def setUp(self):
        self.sln = Solution()

    def test_zero(self):
        self.assertEqual("", self.sln.intToRoman(0))

    def test_one_to_five(self):
        # self.assertEqual("I", self.sln.intToRoman(1))
        self.assertEqual("II", self.sln.intToRoman(2))
        self.assertEqual("III", self.sln.intToRoman(3))
        self.assertEqual("IV", self.sln.intToRoman(4))
        self.assertEqual("V", self.sln.intToRoman(5))

    def test_leetcode(self):
        self.assertEquals("IX", self.sln.intToRoman(9))
        self.assertEquals("LVIII", self.sln.intToRoman(58))
        self.assertEquals("MCMXCIV", self.sln.intToRoman(1994))
        self.assertEquals("MMMCMXCIX", self.sln.intToRoman(3999))

    def test_leetcode_fails(self):
        self.assertEquals("X", self.sln.intToRoman(10))
Ejemplo n.º 3
0
 def testInputBiggerThan50NotRoundNumber(self):
     input = 96
     expectedResult = "XCVI"
     solution = Solution()
     actualSolution = solution.intToRoman(input)
     self.assertEqual(expectedResult, actualSolution)
Ejemplo n.º 4
0
 def testInputBiggerThan50RoundNumber(self):
     input = 80
     expectedResult = 'LXXX'
     solution = Solution()
     actualSolution = solution.intToRoman(input)
     self.assertEqual(expectedResult, actualSolution)
Ejemplo n.º 5
0
 def testInputBiggerThan50(self):
     input = 61
     expectedResult = 'LXI'
     solution = Solution()
     actualSolution = solution.intToRoman(input)
     self.assertEqual(expectedResult, actualSolution)
Ejemplo n.º 6
0
 def testInputSmallerThan50NotRound2(self):
     input = 48
     expectedResult = "XLVIII"
     solution = Solution()
     actualSolution = solution.intToRoman(input)
     self.assertEqual(expectedResult, actualSolution)
Ejemplo n.º 7
0
 def testInputSmallerThan50(self):
     input = 20
     expectedResult = 'XX'
     solution = Solution()
     actualSolution = solution.intToRoman(input)
     self.assertEqual(expectedResult, actualSolution)
Ejemplo n.º 8
0
 def testInputEqualTo50(self):
     input = 50
     expectedResult = 'L'
     solution = Solution()
     actualSolution = solution.intToRoman(input)
     self.assertEqual(expectedResult, actualSolution)
Ejemplo n.º 9
0
 def testBiggerThan4SamllerThan10(self):
     input = 8
     expectedResult = 'VIII'
     solution = Solution()
     actualSolution = solution.intToRoman(input)
     self.assertEqual(expectedResult, actualSolution)
Ejemplo n.º 10
0
 def setUp(self):
     self.sln = Solution()
Ejemplo n.º 11
0
""" Generating a number in range [1, 3999], converting it to Roman numeral,
generating number from Roman numeral and comparing it with original number.
"""
import random
from integer_to_roman import Solution as SolIntRom
from roman_to_integer import Solution as SolRomInt

sol_int_rom = SolIntRom()
sol_rom_int = SolRomInt()

while True:
    # generate random number from 1 to 3999
    original_number = random.randrange(1, 4000)

    # convert number to roman numeral
    roman_number = sol_int_rom.int_to_roman(original_number)

    # convert roman numeral back to integer
    converted_number = sol_rom_int.roman_to_int(roman_number)

    # compare with original number
    if converted_number == original_number:
        print("OK")
        print(f"original number: {original_number}")
        print(f"roman number: {roman_number}")
        print()
    else:
        print("Conversion results are different.")
        print(f"original number: {original_number}")
        print(f"roman number: {roman_number}")
        print(f"converted number: {converted_number}")
Ejemplo n.º 12
0
 def test_int_to_roman(self):
     outs = ('III', 'IV', 'IX', 'LVIII', 'MCMXCIV')
     inputs = (3, 4, 9, 58, 1994)
     for inp, out in zip(inputs, outs):
         self.assertEqual(out, Solution().intToRoman(inp))