Fix a bug with roman literals conversion
This commit is contained in:
parent
08599d91de
commit
27d601ca21
@ -51,7 +51,17 @@ class TestTexts(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"MCMLXXXVII",
|
"XXXIX",
|
||||||
|
tools.convert_arabic_to_roman("39")
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
"40",
|
||||||
|
tools.convert_arabic_to_roman("40")
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
"1987",
|
||||||
tools.convert_arabic_to_roman("1987")
|
tools.convert_arabic_to_roman("1987")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -85,6 +95,16 @@ class TestTexts(unittest.TestCase):
|
|||||||
tools.normalize_string("Dans le 15e arrondissement")
|
tools.normalize_string("Dans le 15e arrondissement")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
"paris XVe, 75005",
|
||||||
|
tools.normalize_string("Paris 15e, 75005")
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
"paris xve, 75005",
|
||||||
|
tools.normalize_string("Paris XVe, 75005")
|
||||||
|
)
|
||||||
|
|
||||||
def test_multiple_whitespaces(self):
|
def test_multiple_whitespaces(self):
|
||||||
"""
|
"""
|
||||||
Checks whitespaces are collapsed.
|
Checks whitespaces are collapsed.
|
||||||
|
@ -27,7 +27,8 @@ NAVITIA_ENDPOINT = "https://api.navitia.io/v1/coverage/fr-idf/journeys"
|
|||||||
|
|
||||||
def convert_arabic_to_roman(arabic):
|
def convert_arabic_to_roman(arabic):
|
||||||
"""
|
"""
|
||||||
Convert an arabic literal to a roman one.
|
Convert an arabic literal to a roman one. Limits to 39, which is a rough
|
||||||
|
estimate for a maximum for using roman notations in daily life.
|
||||||
|
|
||||||
..note::
|
..note::
|
||||||
Based on https://gist.github.com/riverrun/ac91218bb1678b857c12.
|
Based on https://gist.github.com/riverrun/ac91218bb1678b857c12.
|
||||||
@ -35,14 +36,12 @@ def convert_arabic_to_roman(arabic):
|
|||||||
:param arabic: An arabic number, as string.
|
:param arabic: An arabic number, as string.
|
||||||
:returns: The corresponding roman one, as string.
|
:returns: The corresponding roman one, as string.
|
||||||
"""
|
"""
|
||||||
|
if int(arabic) > 39:
|
||||||
|
return arabic
|
||||||
|
|
||||||
to_roman = {
|
to_roman = {
|
||||||
1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V', 6: 'VI', 7: 'VII',
|
1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V', 6: 'VI', 7: 'VII',
|
||||||
8: 'VIII', 9: 'IX', 10: 'X',
|
8: 'VIII', 9: 'IX', 10: 'X', 20: 'XX', 30: 'XXX'
|
||||||
20: 'XX', 30: 'XXX', 40: 'XL', 50: 'L', 60: 'LX', 70: 'LXX',
|
|
||||||
80: 'LXXX', 90: 'XC',
|
|
||||||
100: 'C', 200: 'CC', 300: 'CCC', 400: 'CD', 500: 'D', 600: 'DC',
|
|
||||||
700: 'DCC', 800: 'DCCC', 900: 'CM',
|
|
||||||
1000: 'M', 2000: 'MM', 3000: 'MMM'
|
|
||||||
}
|
}
|
||||||
roman_chars_list = []
|
roman_chars_list = []
|
||||||
count = 1
|
count = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user