Beispiel #1
0
 def test_to_roman(self):
     self.assertEqual('I', roman.to_roman(1))
     self.assertEqual('III', roman.to_roman(3))
     self.assertEqual('IV', roman.to_roman(4))
     self.assertEqual('V', roman.to_roman(5))
     self.assertEqual('VIII', roman.to_roman(8))
     self.assertEqual('IX', roman.to_roman(9))
     self.assertEqual('X', roman.to_roman(10))
     self.assertEqual('L', roman.to_roman(50))
     self.assertEqual('CDXLIV', roman.to_roman(444))
     self.assertEqual('MMMCMXCIX', roman.to_roman(3999))
Beispiel #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)
Beispiel #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_to_roman_known_values(self):
     '''
     to_roman should give known result with known input
     '''
     for integer, numeral in self.known_values:
         result = roman.to_roman(integer)
         self.assertEqual(numeral, result)
 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())
Beispiel #6
0
 def test_roman_combinations(self):
     self.assertEqual('II', to_roman(2))
     self.assertEqual('XXX', to_roman(30))
     self.assertEqual('VI', to_roman(6))
     self.assertEqual('LXII', to_roman(62))
     self.assertEqual('CII', to_roman(102))
     self.assertEqual('DLXXIII', to_roman(573))
     self.assertEqual('MDCLXXXVI', to_roman(1686))
     self.assertEqual('MMMCMXCIX', to_roman(3999))
Beispiel #7
0
 def test_roman_digits(self):
     self.assertEqual('I', to_roman(1))
     self.assertEqual('V', to_roman(5))
     self.assertEqual('X', to_roman(10))
     self.assertEqual('L', to_roman(50))
     self.assertEqual('C', to_roman(100))
     self.assertEqual('D', to_roman(500))
     self.assertEqual('M', to_roman(1000))
Beispiel #8
0
 def test_other_numbers(self):
     self.assertEquals("XXVII", to_roman(27))
     self.assertEquals("LXXXIX", to_roman(89))
     self.assertEquals("CXLV", to_roman(145))
     self.assertEquals("DCXCI", to_roman(691))
     self.assertEquals("MCMLXXXIII", to_roman(1983))
     self.assertEquals("MMCDXII", to_roman(2412))
     self.assertEquals("MMMCCCIX", to_roman(3309))
Beispiel #9
0
def convert(num):
    try:
        return roman.to_roman(num)
    except roman.OutOfRangeError:
        return "Out of range"
    except roman.NotIntegerError:
        return "Not an integer"
    except roman.InvalidRomanNumeralError:
        return "Not a valid roman numeral"
    except Exception:
        return "Error during conversion"
Beispiel #10
0
 def test_to_roman_positive(self):
     self.assertEqual('I', roman.to_roman(1))
     self.assertEqual('XIII', roman.to_roman(13))
     self.assertEqual('CXI', roman.to_roman(111))
     self.assertEqual('MMI', roman.to_roman(2001))
     self.assertEqual('M_V_CMXCIX', roman.to_roman(4999))
     self.assertEqual('_V_', roman.to_roman(5000))
Beispiel #11
0
 def test_roman_exceptions(self):
     self.assertEqual('IV', to_roman(4))
     self.assertEqual('IX', to_roman(9))
     self.assertEqual('XL', to_roman(40))
     self.assertEqual('XC', to_roman(90))
     self.assertEqual('CD', to_roman(400))
     self.assertEqual('CM', to_roman(900))
Beispiel #12
0
def test_roman_out_of_range():
    with pytest.raises(AssertionError):
        to_roman(0)
    with pytest.raises(AssertionError):
        to_roman(4000)
    with pytest.raises(AssertionError):
        to_roman(-100)
Beispiel #13
0
def test_roman_wrong_input():
    with pytest.raises(AssertionError):
        to_roman('123')
    with pytest.raises(AssertionError):
        to_roman(5.0)
    with pytest.raises(AssertionError):
        to_roman('ABCDEF')
Beispiel #14
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))
Beispiel #15
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))
Beispiel #16
0
def parse_page_labels(page_labels: PdfArray, number_pages: int) -> List[str]:
    page_numbers = []

    # add the final stop position
    page_labels.append(number_pages)

    for i in range(0, len(page_labels) - 1, 2):
        start, options, stop = page_labels[i:i + 3]
        stop = int(stop)
        start = int(start)

        # /S specifies the numbering style for page numbers:
        #   /D - Arabic numerals (1,2,3...)
        #   /r - lowercase Roman numerals (i, ii, iii,...)
        #   /R - uppercase Roman numerals (I, II, III,...)
        #   /A - uppercase letters (A-Z)
        #   /a - lowercase letters (a-z)
        # /P (optional) - page number prefix
        # /St (optional) - the value of the first page number in the range (default: 1)
        page_offset = int(options.St or 1)
        page_range = range(page_offset, (stop - start) + 1)

        option_mapping = {
            "/D": str,
            "/r": lambda x: to_roman(x).lower(),
            "/R": to_roman,
            "/a": ascii_lowercase.__getitem__,
            "/A": ascii_uppercase.__getitem__,
        }

        range_numbers = map(option_mapping.get(options.S), page_range)
        if options.P is not None and options.P != "()":
            range_numbers = map(lambda x: options.P + x, range_numbers)

        page_numbers.extend(range_numbers)

    return page_numbers
Beispiel #17
0
 def test_arabic_3_to_roman_III(self):
     self.assertEqual(roman.to_roman(3), "III")
Beispiel #18
0
def test_2():
    assert "II" == to_roman(2)
Beispiel #19
0
def test_all():
    for i in range(1, 4000):
        assert i == to_arabic(to_roman(i))
Beispiel #20
0
def test_402():
    assert "CDII" == to_roman(402)
Beispiel #21
0
def test_911():
    assert "CMXI" == to_roman(911)
Beispiel #22
0
 def test_arabic_777_to_roman_DCCLXXVII(self):
     self.assertEqual(roman.to_roman(777), "DCCLXXVII")
Beispiel #23
0
 def test_fourteen(self):
     self.assertEquals("XIV", to_roman(14))
Beispiel #24
0
 def test_nine_hundred(self):
     self.assertEquals("CM", to_roman(900))
Beispiel #25
0
 def test_one_thousand(self):
     self.assertEquals("M", to_roman(1000))
Beispiel #26
0
 def test_four_hundred(self):
     self.assertEquals("CD", to_roman(400))
Beispiel #27
0
 def test_five_hundred(self):
     self.assertEquals("D", to_roman(500))
Beispiel #28
0
 def test_zero(self):
     self.assertEquals("", to_roman(0))
Beispiel #29
0
 def test_hundred(self):
     self.assertEquals("C", to_roman(100))
Beispiel #30
0
 def test_ninety(self):
     self.assertEquals("XC", to_roman(90))
Beispiel #31
0
 def test_arabic_8_to_roman_VIII(self):
     self.assertEqual(roman.to_roman(8), "VIII")
Beispiel #32
0
 def test_five(self):
     self.assertEquals("V", to_roman(5))
Beispiel #33
0
 def test_arabic_13_to_roman_XIII(self):
     self.assertEqual(roman.to_roman(13), "XIII")
Beispiel #34
0
 def test_one(self):
     self.assertEquals("I", to_roman(1))
Beispiel #35
0
 def test_fifty(self):
     self.assertEquals("L", to_roman(50))
Beispiel #36
0
 def test_four(self):
     self.assertEquals("IV", to_roman(4))
Beispiel #37
0
 def test_ten(self):
     self.assertEquals("X", to_roman(10))
 def test_to_roman_known_values(self):
     '''to_roman 已知结果测试'''
     for integer, numeral in self.known_values:
         result = roman.to_roman(integer)
         self.assertEqual(numeral, result)
Beispiel #39
0
def test_575():
    assert "DLXXV" == to_roman(575)
Beispiel #40
0
 def test_three(self):
     self.assertEquals("III", to_roman(3))
Beispiel #41
0
def test_1024():
    assert "MXXIV" == to_roman(1024)
Beispiel #42
0
 def test_two(self):
     self.assertEquals("II", to_roman(2))
Beispiel #43
0
def test_3000():
    assert "MMM" == to_roman(3000)
Beispiel #44
0
 def test_fourty(self):
     self.assertEquals("XL", to_roman(40))
Beispiel #45
0
"""
    Código de exemplo para uso do pacote de conversão:
        Romano -> Decimal
        Decimal -> Romano
"""

import roman

if __name__ == '__main__':
    print('--- Romano para Decimal ---')

    value = 'CMXCVIII'
    converted = roman.to_decimal(value)

    print(f'{value} -> {converted}')

    print('\n')

    print('--- Decimal para Romano ---')

    value = 998
    converted = roman.to_roman(value)

    print(f'{value} -> {converted}')
Beispiel #46
0
 def test_arabic_7949_to_roman_MMMMMMMCMXLIX(self):
     self.assertEqual(roman.to_roman(7949), "MMMMMMMCMXLIX")
Beispiel #47
0
 def test_arabic_4_to_roman_IV(self):
     self.assertEqual(roman.to_roman(4), "IV")
Beispiel #48
0
 def test_arabic_zero_to_roman_empty(self):
     self.assertEqual(roman.to_roman(0), "")
Beispiel #49
0
 def test_arabic_9_to_roman_IX(self):
     self.assertEqual(roman.to_roman(9), "IX")
Beispiel #50
0
 def test_arabic_1_to_roman_I(self):
     self.assertEqual(roman.to_roman(1), "I")
Beispiel #51
0
 def test_arabic_47_to_roman_XLVII(self):
     self.assertEqual(roman.to_roman(47), "XLVII")
Beispiel #52
0
 def test_nine(self):
     self.assertEquals("IX", to_roman(9))
Beispiel #53
0
 def test_arabic_1987_to_roman_MCMLXXXVII(self):
     self.assertEqual(roman.to_roman(1987), "MCMLXXXVII")
Beispiel #54
0
 def test_fourty_four(self):
     self.assertEquals("XLIV", to_roman(44))
Beispiel #55
0
 def test_arabic_minus_to_roman_ERROR(self):
     self.assertEqual(roman.to_roman(-10), "")
Beispiel #56
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)
Beispiel #57
0
 def test_pi_to_roman_empty(self):
     self.assertEqual(roman.to_roman(math.pi), "III")
Beispiel #58
0
 def test_to_roman_known_value(self):
     """to_roman should return known value from known input."""
     for integer, numeral in self.known_values:
         result = roman.to_roman(integer)
         self.assertEqual(numeral, result)
Beispiel #59
0
 def test_to_roman_known_values(self):           
     '''to_roman should give known result with known input'''
     for integer, numeral in self.known_values:
         result = roman.to_roman(integer)       
         self.assertEqual(numeral, result) 
Beispiel #60
0
 def test_six(self):
     self.assertEquals("VI", to_roman(6))