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-+/-'))
def evaluate(self): sh = ShuntingYard(self.operations) self.stack = sh.stack
def testShuntingYardParanthesis(self): formular = Formular("(5 + 3) * 8") sh = ShuntingYard(formular.operations) sh.evaluate() self.assertEqual(sh.stack, list('53+8*'))
def testShuntingYardAdditionMultiplication(self): formular = Formular("5 + 3 * 8") sh = ShuntingYard(formular.operations) sh.evaluate() self.assertEqual(sh.stack, list('538*+'))
def testShuntingYardDivision(self): formular = Formular("8 / 3") sh = ShuntingYard(formular.operations) sh.evaluate() self.assertEqual(sh.stack, list('83/'))
def testShuntingYardMultiplication(self): formular = Formular("5 * 4") sh = ShuntingYard(formular.operations) sh.evaluate() self.assertEqual(sh.stack, list('54*'))
def testShuntingYardSubtraction(self): formular = Formular("8 - 3") sh = ShuntingYard(formular.operations) sh.evaluate() self.assertEqual(sh.stack, list('83-'))
def testShuntingYardCall(self): sh = ShuntingYard(list('5+3')) sh.evaluate() self.assertEqual(sh.stack, list('53+'))