Exemplo n.º 1
0
    def testShuntingYardAllOperations(self):
        math = "1 + 2 - 3 * 4 / (5 + (6 - 7)) "
        formular = Formular(math)
        sh = ShuntingYard(formular.operations)
        sh.evaluate()

        self.assertEqual(sh.stack, list('12+34*567-+/-'))
Exemplo n.º 2
0
 def evaluate(self):
     sh = ShuntingYard(self.operations)
     self.stack = sh.stack
Exemplo n.º 3
0
 def testShuntingYardParanthesis(self):
     formular = Formular("(5 + 3) * 8")
     sh = ShuntingYard(formular.operations)
     sh.evaluate()
     self.assertEqual(sh.stack, list('53+8*'))
Exemplo n.º 4
0
 def testShuntingYardAdditionMultiplication(self):
     formular = Formular("5 + 3 * 8")
     sh = ShuntingYard(formular.operations)
     sh.evaluate()
     self.assertEqual(sh.stack, list('538*+'))
Exemplo n.º 5
0
 def testShuntingYardDivision(self):
     formular = Formular("8 / 3")
     sh = ShuntingYard(formular.operations)
     sh.evaluate()
     self.assertEqual(sh.stack, list('83/'))
Exemplo n.º 6
0
 def testShuntingYardMultiplication(self):
     formular = Formular("5 * 4")
     sh = ShuntingYard(formular.operations)
     sh.evaluate()
     self.assertEqual(sh.stack, list('54*'))
Exemplo n.º 7
0
 def testShuntingYardSubtraction(self):
     formular = Formular("8 - 3")
     sh = ShuntingYard(formular.operations)
     sh.evaluate()
     self.assertEqual(sh.stack, list('83-'))
Exemplo n.º 8
0
 def testShuntingYardCall(self):
     sh = ShuntingYard(list('5+3'))
     sh.evaluate()
     self.assertEqual(sh.stack, list('53+'))