-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathar2rom.py
49 lines (35 loc) · 985 Bytes
/
ar2rom.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
import unittest
conversion_map = (
('x', 10),
('ix', 9),
('v', 5),
('iv', 4),
('i', 1))
def ar2rom(val):
res = ''
for rom, ar in conversion_map:
while val >= ar:
res += rom
val -= ar
return res
class Tests(unittest.TestCase):
def test_1_to_i(self):
self.assertEqual(ar2rom(1), 'i')
def test_2_to_ii(self):
self.assertEqual(ar2rom(2), 'ii')
def test_3_to_iii(self):
self.assertEqual(ar2rom(3), 'iii')
def test_4_to_iv(self):
self.assertEqual(ar2rom(4), 'iv')
def test_5_to_v(self):
self.assertEqual(ar2rom(5), 'v')
def test_9_to_ix(self):
self.assertEqual(ar2rom(9), 'ix')
def test_10_to_x(self):
self.assertEqual(ar2rom(10), 'x')
def test_20_to_xx(self):
self.assertEqual(ar2rom(20), 'xx')
def test_21_to_xxi(self):
self.assertEqual(ar2rom(21), 'xxi')
if __name__ == "__main__":
unittest.main()