Exemplo n.º 1
0
def t_ID(t):
    r'[_a-zA-Z][_a-zA-Z0-9]*'
    num = Roman.fromRoman(t.value)

    if num is None:
        t.type = 'ID'

    else:
        t.type = 'INTEGER'
        t.value = num

    return t
Exemplo n.º 2
0
def p_statement_expr(p):
    'statement : expression'
    baseInfo = {2: '0b{0:b}', 8: '0o{0:o}', 16: '0x{0:x}'}
    try:
        iNum = int(p[1])

        if p[1] == iNum:
            if names.get('printRoman', 0):
                print(Roman.toRoman(iNum), f'({iNum})')

            else:
                fmt = baseInfo.get(names.get('printBase', 10), '{0}')
                print(fmt.format(iNum))

        else:
            print(p[1])

    except:
        print(p[1])
def step_impl(context):
    context.roman = Roman()
Exemplo n.º 4
0
 def test_partition_12(self):
     self.number = Roman(12)
     self.assertEqual(self.number._Roman__partition(), [12])
Exemplo n.º 5
0
 def test_convert_63925(self):
     self.number = Roman(63925)
     self.assertEqual(self.number._Roman__convert(), '(LXIII)(1)CMXXV')
Exemplo n.º 6
0
 def test_convert_14000022(self):
     self.number = Roman(14000022)
     self.assertEqual(self.number._Roman__convert(), '(XIV)(2)XXII')
Exemplo n.º 7
0
 def test_convert_123(self):
     self.number = Roman(123)
     self.assertEqual(self.number._Roman__convert(), 'CXXIII')
Exemplo n.º 8
0
 def setUp(self):
     self.roman = Roman(1)
Exemplo n.º 9
0
class Romantest(unittest.TestCase):
    def setUp(self):
        self.roman = Roman(1)

    def test_partition_12(self):
        self.number = Roman(12)
        self.assertEqual(self.number._Roman__partition(), [12])

    def test_partition_123(self):
        self.number = Roman(123)
        self.assertEqual(self.number._Roman__partition(), [123])

    def test_partition_1234(self):
        self.number = Roman(1234)
        self.assertEqual(self.number._Roman__partition(), [234, 1])

    def test_partition_123456(self):
        self.number = Roman(123456)
        self.assertEqual(self.number._Roman__partition(), [456, 123])

    def test_partition_1234567(self):
        self.number = Roman(1234567)
        self.assertEqual(self.number._Roman__partition(), [567, 234, 1])


    def test_translateGroup_122(self):
        self.assertEqual(self.roman._Roman__translateGroup(122, 0), ('CXXII', 0))

    def test_translateGroup_4(self):
        self.assertEqual(self.roman._Roman__translateGroup(4, 1), ('MMMM', 0))

    def test_translateGroup_5(self):
        self.assertEqual(self.roman._Roman__translateGroup(5, 1), ('V', 1))

    def test_translateGroup_34(self):
        self.assertEqual(self.roman._Roman__translateGroup(34, 2), ('XXXIV', 2))


    def test_convert_123(self):
        self.number = Roman(123)
        self.assertEqual(self.number._Roman__convert(), 'CXXIII')

    def test_convert_63925(self):
        self.number = Roman(63925)
        self.assertEqual(self.number._Roman__convert(), '(LXIII)(1)CMXXV')

    def test_convert_14000022(self):
        self.number = Roman(14000022)
        self.assertEqual(self.number._Roman__convert(), '(XIV)(2)XXII')
Exemplo n.º 10
0
 def test_partition_1234567(self):
     self.number = Roman(1234567)
     self.assertEqual(self.number._Roman__partition(), [567, 234, 1])
Exemplo n.º 11
0
 def test_partition_123456(self):
     self.number = Roman(123456)
     self.assertEqual(self.number._Roman__partition(), [456, 123])