def testComplex(self):
     arr = [
         "+", "11", "-", "4", "+", "5", "*", "2", "-", "12", "/", "4", "+",
         "11", "*", "12", "*", "15"
     ]
     expected = 1994.0
     self.assertEqual(expected, solve_expression(arr))
 def testInBracket(self):
     expected = 15
     arr = ["(", "12", "+", "3", ")"]
     self.assertEqual(expected, solve_expression(arr))
 def testBrackets_negative_in_brackets(self):
     expected = -220
     arr = ["+", "5", "*", "(", "11", "*", "(", "-", "4", ")", ")"]
     self.assertEqual(expected, solve_expression(arr))
 def testBrackets_mult2x(self):
     expected = 220
     arr = ["+", "5", "*", "(", "11", "*", "4", ")"]
     self.assertEqual(expected, solve_expression(arr))
 def testBrackets_plus(self):
     expected = 11
     arr = ["+", "5", "+", "(", "10", "-", "4", ")"]
     self.assertEqual(expected, solve_expression(arr))
 def testManyDivides(self):
     expected = 140 / 5 / 6
     arr = ["+", "140", "/", "5", "/", "6"]
     self.assertEqual(expected, solve_expression(arr))
 def testManyMultiplications(self):
     expected = 1980.0
     arr = ["+", "11", "*", "12", "*", "15"]
     self.assertEqual(expected, solve_expression(arr))
 def test7(self):
     arr = ["+", "11", "-", "4"]
     expected = 7.0
     self.assertEqual(expected, solve_expression(arr))
 def test5(self):
     arr = ["+", "0", "-", "5", "*", "3"]
     expected = -15.0
     self.assertEqual(expected, solve_expression(arr))
 def test1(self):
     arr = ["+", "5", "+", "3"]
     expected = 8.0
     self.assertEqual(expected, solve_expression(arr))
 def test3(self):
     arr = ["+", "11", "*", "12", "+", "5"]
     expected = 137.0
     self.assertEqual(expected, solve_expression(arr))
 def test2(self):
     arr = ["+", "12", "/", "4"]
     expected = 3.0
     self.assertEqual(expected, solve_expression(arr))
 def testOneNegativeNumber(self):
     arr = ["-", "5"]
     expected = -5.0
     self.assertEqual(expected, solve_expression(arr))
 def testEmpty(self):
     arr = ["+", "0"]
     expected = 0.0
     self.assertEqual(expected, solve_expression(arr))
Ejemplo n.º 15
0
# This is a sample Python script.
from CustomExceptionClass import GeneralError, NotAllowedSymbol
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

from GetTokens import GetTokens
from Solver import solve_expression

if __name__ == '__main__':
    expression = input()
    try:
        tokens = GetTokens(expression)
        print(solve_expression((tokens)))
    except GeneralError as x:
        print(x)