-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathRomanNumberConverter.py
52 lines (35 loc) · 1.27 KB
/
RomanNumberConverter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class RomanNumeralConverter(object):
"""
The Roman Numeral Converter only applies rules of addition.
"""
def __init__(self, roman_numeral):
self.roman_numeral = roman_numeral
self.digit_map = {"M": 1000, "D": 500, "C": 100, "L": 50, "X": 10, "V": 5, "I": 1}
# TODO: Implement Substraction
def convert_to_decimal(self):
val = 0
for char in self.roman_numeral:
val += self.digit_map[char]
return val
def test_parsing_millenia():
value = RomanNumeralConverter("M")
assert value.convert_to_decimal() == 1000
def test_parsing_half_millenia():
value = RomanNumeralConverter("D")
assert value.convert_to_decimal() == 500
def test_parsing_century():
value = RomanNumeralConverter("C")
assert value.convert_to_decimal() == 100
def test_parsing_half_century():
value = RomanNumeralConverter("L")
assert value.convert_to_decimal() == 50
def test_parsing_decade():
value = RomanNumeralConverter("X")
assert value.convert_to_decimal() == 10
def test_parsing_half_decade():
value = RomanNumeralConverter("V")
assert value.convert_to_decimal() == 5
# FIXME: Test Fails
def test_parsing_one():
value = RomanNumeralConverter("I")
assert value.convert_to_decimal() == 1