def test_from_roman_case(self) :
     """from_roman should only accept uppercase input"""
     for intgr in range(1, 4000) :
         numeral = roman.to_roman(intgr)
         roman.from_roman(numeral.upper())
         self.assertRaises(roman.InvalidRomanNumeralError,
                           roman.from_roman, numeral.lower())
示例#2
0
    def test_roundtrip(self):
        '''from_roman(to_roman(n)) == n for all n'''
        for integer in range(1, 5000):
            numeral = roman.to_roman(integer)
            result = roman.from_roman(numeral)

            self.assertEqual(integer, result)
示例#3
0
    def test_roundtrip(self):
		'''from_roman(to_roman(n))==n for all n'''

		for integer in range(1, 4000):
			numeral = roman.to_roman(integer)
			result = roman.from_roman(numeral)
			self.assertEqual(integer, result)
 def test_from_roman_known_values(self):
     '''
     from_roman should give known result with known input
     '''
     for integer, numeral in self.known_values:
         result = roman.from_roman(numeral)
         self.assertEqual(integer, result)
示例#5
0
    def on_convert_clicked(self, widget):
        input_text = self.entry_input.get_text()
        output_text = ""

        print(input_text, type(input_text), self.mode)

        # Numeral output mode
        if self.mode == "numeral":
            print("to_roman(", int(input_text), ")")
            output_text = roman.to_roman(int(input_text))
        # Integer output mode
        elif self.mode == "integer":
            print("from_roman(", input_text, ")")
            output_text = roman.from_roman(input_text)

        self.entry_output.set_text(str(output_text))
示例#6
0
def convert(num, source_system, dest_system, args=None):
    if source_system == SysNames.int:
        return convertFromInt(int(num), dest_system, args)

    if source_system == SysNames.hex:
        return convertFromInt(int(num, 16), dest_system, args)

    if source_system == SysNames.binary:
        return convertFromInt(int(num, 2), dest_system, args)

    if source_system == SysNames.roman:
        return convertFromInt(roman.from_roman(num), dest_system, args)

    if (source_system == SysNames.ipv4) or (source_system == SysNames.ipv6):
        ipaddress = ip_address(num)
        return convertFromInt(int(ipaddress), dest_system, args)

    return "No conversion applicable"
示例#7
0
def main():
    '''Main program entry point'''

    # Run our command line argument parser and collect the results into an object
    args = parse_command_line_args()

    # Print some extra information if you like
    if args.verbose:
        print('Number: {0}'.format(args.number))
        print('Numeral: {0}'.format(args.numeral))
        print('Integer: {0}'.format(args.integer))

    # If we are converting to Roman  numeral..
    if args.numeral:
        print(roman.to_roman(int(args.number)))
    # If we are converting to integer..
    elif args.integer:
        print(roman.from_roman(args.number))
示例#8
0
 def test_from_rmona(self):
   for integer, numeral in self.knownValues:
     result = roman.from_roman(numeral)
     self.assertEqual(result, integer)
示例#9
0
 def testFromRomanKnownValues(self):
     """fromRoman should give known result with known input"""
     for integer, numeral in self.knownValues:
         result = roman.from_roman(numeral)
         self.assertEqual(integer, result)
示例#10
0
 def testfrom_romanCase(self):
     for integer in range(1, 4000):
         numeral = roman.to_roman(integer)
         roman.from_roman(numeral.upper())
         self.assertRaises(roman.InvalidRomanNumeralError, roman.from_roman,
                           numeral.lower())
示例#11
0
 def testSanity(self):
     for integer in range(1, 4000):
         numeral = roman.to_roman(integer)
         result = roman.from_roman(numeral)
         self.assertEqual(integer, result)
示例#12
0
 def test_from_rmona(self):
     for integer, numeral in self.knownValues:
         result = roman.from_roman(numeral)
         self.assertEqual(result, integer)
示例#13
0
 def test_roundtrip(self):
     '''test from_roman(to_roman(n)) == n for all n'''
     for digit_numeral in range(1, roman.MAX_ROMAN):
         roman_numeral = roman.to_roman(digit_numeral)
         result = roman.from_roman(roman_numeral)
         self.assertEqual(digit_numeral, result)
示例#14
0
 def test_from_roman_known_values(self):
     '''from_roman should give known result to known input '''
     for digit_numeral, roman_numeral in self.known_values:
         result = roman.from_roman(roman_numeral)
         self.assertEqual(result, digit_numeral)
 def test_fromRoman(self):
     for intgr, rmn in self.known_values :
         result = roman.from_roman(rmn)
         self.assertEqual(intgr, result)
示例#16
0
 def testFromRomanKnownValues(self):
     """fromRoman should give known result with known input"""
     for integer, numeral in self.knownValues:
         result = roman.from_roman(numeral)
         self.assertEqual(integer, result)
示例#17
0
 def test_roundtrip(self):
     """from_roman(to_roman(n)) == n for all n 1..3999."""
     for integer in range(1, 5000):
         numeral = roman.to_roman(integer)
         result = roman.from_roman(numeral)
         self.assertEqual(integer, result)
示例#18
0
 def test_from_roman_known_values(self):
     """from_roman should give known result with known value"""
     for integer, numeral in self.known_values:
         result = roman.from_roman(numeral)
         self.assertEqual(result, integer)
示例#19
0
 def testfrom_romanCase(self):
   for integer in range(1, 4000):
     numeral = roman.to_roman(integer)
     roman.from_roman(numeral.upper())
     self.assertRaises(roman.InvalidRomanNumeralError,
         roman.from_roman, numeral.lower())
示例#20
0
    def test_known_values(self):
        '''from_roman should return known output for known input'''

        for integer, numeral in known_values:
            self.assertEqual(from_roman(numeral), integer)
示例#21
0
 def test_round_trip(self):
     '''Test all allowable input for to/from_roman is equal'''
     for integer in range(1, 4999):
         numeral = roman.to_roman(integer)
         result = roman.from_roman(numeral)
         self.assertEqual(integer, result)
示例#22
0
 def test_from_roman_known_values(self):
     '''from_roman 已知结果测试'''
     for integer, numeral in self.known_values:
         result = roman.from_roman(numeral)
         self.assertEqual(integer, result)
示例#23
0
 def testSanity(self):
   for integer in range(1, 4000):
     numeral = roman.to_roman(integer)
     result = roman.from_roman(numeral)
     self.assertEqual(integer, result)
示例#24
0
 def test_from_roman_known_value(self):
     """from_roman should return known value from known input."""
     for integer, numeral in self.known_values:
         result = roman.from_roman(numeral)
         self.assertEqual(integer, result)
 def test_roundtrip(self):
     for integer in range(1,5000):
         numeral = roman.to_roman(integer)
         result = roman.from_roman(numeral)
         self.assertEqual(integer, result)
示例#26
0
 def test_from_roman_known_values(self):
     '''from_roman should give known result with known input'''
     for integer, numeral in self.known_values:
         result = roman.from_roman(numeral)
         self.assertEqual(integer, result)
 def test_sanity(self) :
     """from_roman(to_roman(n))==n for all n"""
     for intgr in range(1, 4000) :
         numeral = roman.to_roman(intgr)
         result = roman.from_roman(numeral)
         self.assertEqual(intgr, result)