コード例 #1
0
 def sum_alien_numerals(self, alien_numerals):
     """
     Return the sum of alien numerals
     
     :alien_numerals: a list containing alien numerals
     E.g. ["glob", "glob"]
     """
     try:
         roman_numeral = reduce(
             lambda first_value, second_value: first_value + second_value,
             [self.alien_numerals[alien_numeral]['roman']
             for alien_numeral in alien_numerals])
         number = roman_to_numeral(roman_numeral)
     except Exception:
         raise InvalidAlienNumeralError(
             'Invalid Alien numeral: "%s"' % alien_numerals)
     return number
コード例 #2
0
 def sum_alien_numerals(self, alien_numerals):
     """
     Return the sum of alien numerals
     
     :alien_numerals: a list containing alien numerals
     E.g. ["glob", "glob"]
     """
     try:
         roman_numeral = reduce(
             lambda first_value, second_value: first_value + second_value, [
                 self.alien_numerals[alien_numeral]['roman']
                 for alien_numeral in alien_numerals
             ])
         number = roman_to_numeral(roman_numeral)
     except Exception:
         raise InvalidAlienNumeralError('Invalid Alien numeral: "%s"' %
                                        alien_numerals)
     return number
コード例 #3
0
 def __define_alien_numeral_value(self, sentence):
     alien_numeral = re.match(r"^\w+", sentence).group()
     roman_numeral = re.match(r"^\w+", re.sub(r"^\w+ is ", "", sentence)).group()
     self.alien_converter.alien_numerals[alien_numeral] = {'roman': roman_numeral,
                                           'arabic': roman_to_numeral(roman_numeral)}
コード例 #4
0
 def test_roman_to_numeral(self):
     self.assertEqual(roman_to_numeral('I'), 1)
     self.assertEqual(roman_to_numeral('II'), 2)
     self.assertEqual(roman_to_numeral('III'), 3)
     self.assertEqual(roman_to_numeral('IV'), 4)
     self.assertEqual(roman_to_numeral('V'), 5)
     self.assertEqual(roman_to_numeral('VI'), 6)
     self.assertEqual(roman_to_numeral('VII'), 7)
     self.assertEqual(roman_to_numeral('VIII'), 8)
     self.assertEqual(roman_to_numeral('IX'), 9)
     self.assertEqual(roman_to_numeral('X'), 10)
     self.assertEqual(roman_to_numeral('XX'), 20)
     self.assertEqual(roman_to_numeral('XXX'), 30)
     self.assertEqual(roman_to_numeral('XXXVIII'), 38)
     self.assertEqual(roman_to_numeral('XL'), 40)
     self.assertEqual(roman_to_numeral('L'), 50)
     self.assertEqual(roman_to_numeral('LX'), 60)
     self.assertEqual(roman_to_numeral('XCIX'), 99)
     self.assertEqual(roman_to_numeral('C'), 100)
     self.assertEqual(roman_to_numeral('MMXIII'), 2013)
     self.assertEqual(roman_to_numeral('MCMLXXXIII'), 1983)
     self.assertEqual(roman_to_numeral('MMMDCCCLXXXVIII'), 3888)
コード例 #5
0
 def test_roman_to_numeral(self):
     self.assertEqual(roman_to_numeral('I'), 1)
     self.assertEqual(roman_to_numeral('II'), 2)
     self.assertEqual(roman_to_numeral('III'), 3)
     self.assertEqual(roman_to_numeral('IV'), 4)
     self.assertEqual(roman_to_numeral('V'), 5)
     self.assertEqual(roman_to_numeral('VI'), 6)
     self.assertEqual(roman_to_numeral('VII'), 7)
     self.assertEqual(roman_to_numeral('VIII'), 8)
     self.assertEqual(roman_to_numeral('IX'), 9)
     self.assertEqual(roman_to_numeral('X'), 10)
     self.assertEqual(roman_to_numeral('XX'), 20)
     self.assertEqual(roman_to_numeral('XXX'), 30)
     self.assertEqual(roman_to_numeral('XXXVIII'), 38)
     self.assertEqual(roman_to_numeral('XL'), 40)
     self.assertEqual(roman_to_numeral('L'), 50)
     self.assertEqual(roman_to_numeral('LX'), 60)
     self.assertEqual(roman_to_numeral('XCIX'), 99)
     self.assertEqual(roman_to_numeral('C'), 100)
     self.assertEqual(roman_to_numeral('MMXIII'), 2013)
     self.assertEqual(roman_to_numeral('MCMLXXXIII'), 1983)
     self.assertEqual(roman_to_numeral('MMMDCCCLXXXVIII'), 3888)