Пример #1
0
 def test_eval_unary_minus9(self):
     tokens = self._lexer.lex("(-7-3)")
     self.assertEqual(6, len(tokens))
     expression = Expression()
     value = expression.eval(tokens)
     self.assertEqual(-10, value)
Пример #2
0
 def test_eval_unary_minus6(self):
     tokens = self._lexer.lex("--9")
     self.assertEqual(3, len(tokens))
     expression = Expression()
     with self.assertRaises(BasicSyntaxError):
         value = expression.eval(tokens)
Пример #3
0
 def test_eval_unary_minus7(self):
     tokens = self._lexer.lex("(2+3)-1")
     self.assertEqual(7, len(tokens))
     expression = Expression()
     value = expression.eval(tokens)
     self.assertEqual(4, value)
Пример #4
0
 def test_eval_unary_minus5(self):
     tokens = self._lexer.lex("-(2+3)*-(4+5)+-1")
     self.assertEqual(16, len(tokens))
     expression = Expression()
     value = expression.eval(tokens)
     self.assertEqual(44, value)
Пример #5
0
 def test_eval_unary_minus3(self):
     tokens = self._lexer.lex("10*-8")
     self.assertEqual(4, len(tokens))
     expression = Expression()
     value = expression.eval(tokens)
     self.assertEqual(-80, value)
Пример #6
0
 def test_eval_unary_minus2(self):
     tokens = self._lexer.lex("-9*3")
     self.assertEqual(4, len(tokens))
     expression = Expression()
     value = expression.eval(tokens)
     self.assertEqual(-27, value)
Пример #7
0
 def test_eval1(self):
     tokens = self._lexer.lex("1")
     self.assertEqual(1, len(tokens))
     expression = Expression()
     value = expression.eval(tokens)
     self.assertEqual(1, value)
Пример #8
0
 def test_eval_parens5(self):
     tokens = self._lexer.lex("(7-3) * ((2*4) - (2+5))")
     self.assertEqual(19, len(tokens))
     expression = Expression()
     value = expression.eval(tokens)
     self.assertEqual(4, value)