コード例 #1
0
 def parseRoman(self):
     self.numerals = []
     #check for subtractions by creating with pairs at each index
     for numPairs in numeral.Numeral.listValidSubtractions:
         splitLetters = self.roman.split(sep=numPairs, maxsplit=1)
         if len(splitLetters) > 1:
             self.numerals.append(numeral.Numeral(numPairs))
         self.roman = ''.join(splitLetters)
     #Now that subs are removed, add the remaining numerals
     for l in self.roman:
         self.numerals.append(numeral.Numeral(l))
     #sort them, so they should appear in C, XC, X... descending order
     self.numerals.sort(reverse=True)
コード例 #2
0
 def checkSingleSubtraction(self):
     iiIndex = self.roman.find('II')
     xxIndex = self.roman.find('XX')
     ccIndex = self.roman.find('CC')
     checkPassed = True
     if iiIndex > -1:
         checkPassed = self.checkFollowingNumeralsLessThanEqual(
             iiIndex, numeral.Numeral('I'))
     if xxIndex > -1 and checkPassed:
         checkPassed = self.checkFollowingNumeralsLessThanEqual(
             xxIndex, numeral.Numeral('X'))
     if ccIndex > -1 and checkPassed:
         checkPassed = self.checkFollowingNumeralsLessThanEqual(
             ccIndex, numeral.Numeral('C'))
     return checkPassed
コード例 #3
0
 def checkFiveBasedSubtraction(self):
     checkPassed = True
     fiveBasedNumbers = ['V', 'L', 'D']
     for num in fiveBasedNumbers:
         index = self.roman.find(num)
         if index > -1:
             checkPassed = self.checkFollowingNumeralsLessThan(
                 index, numeral.Numeral(num))
     return checkPassed
コード例 #4
0
    def generateRomanNumerals(self):
        self.roman = ''
        self.numerals = []
        remainingNumber = self.arabic

        listDescendingNumerals = [
            'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV',
            'I'
        ]

        #Go get the largest numeral/subtraction pair, and subtract it from the temp
        while remainingNumber > 0:
            for num in listDescendingNumerals:
                if remainingNumber >= numeral.Numeral.dictNumeralValues[num]:
                    self.numerals.append(numeral.Numeral(num))
                    remainingNumber -= numeral.Numeral.dictNumeralValues[num]
                    break

        for num in self.numerals:
            self.roman += num.letter
コード例 #5
0
 def setUp(self):
     self.numeral = numeral.Numeral('D')
コード例 #6
0
 def setUp(self):
     self.numeral_ = numeral.Numeral('I')
コード例 #7
0
 def checkFollowingNumeralsLessThan(self, startIndex, numer):
     for letter in self.roman[startIndex + 1:]:
         num = numeral.Numeral(letter)
         if num.value >= numer.value:
             return False
     return True