示例#1
0
 def test_add_extra_unary_operator_with_max_precedence(self):
   operators = {
     '+': {'precedence': 2, 'associativity': LEFT},
     '-': {'precedence': 2, 'associativity': LEFT},
     '*': {'precedence': 3, 'associativity': LEFT},
     '/': {'precedence': 3, 'associativity': LEFT},
     '^': {'precedence': 4, 'associativity': RIGHT},
     '--':{'precedence': 5, 'associativity': RIGHT},
   }
   expression = "2 -- + 4".split()
   expected = "2 -- 4 +".split()
   actual = reverse_polish_notation(expression, operators, functions)
   self.assertEqual(actual, expected)
示例#2
0
 def test_expression_with_functions(self):
   expression = "sin ( max ( 2 , 3 ) / 3 * 3 )".split()
   expected = "2 3 max 3 / 3 * sin".split()
   actual = reverse_polish_notation(expression, operators, functions)
   self.assertEqual(actual, expected)
示例#3
0
 def test_simple_function_expression(self):
   expression = "max ( 2 , 3 )".split()
   expected = "2 3 max".split()
   actual = reverse_polish_notation(expression, operators, functions)
   self.assertEqual(actual, expected)
示例#4
0
 def test_even_more_complicated_expression(self):
   expression = "3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3".split()
   expected = "3 4 2 * 1 5 - 2 3 ^ ^ / +".split()
   actual = reverse_polish_notation(expression, operators, functions)
   self.assertEqual(actual, expected)
示例#5
0
 def test_complicated_expression(self):
   expression = "5 + ( ( 1 + 2 ) * 4 ) - 3".split()
   expected = "5 1 2 + 4 * + 3 -".split()
   actual = reverse_polish_notation(expression, operators, functions)
   self.assertEqual(actual, expected)
示例#6
0
 def test_simple_paranthesis(self):
   expression = "( 3 - 4 ) * 5".split()
   expected = "3 4 - 5 *".split()
   actual = reverse_polish_notation(expression, operators, functions)
   self.assertEqual(actual, expected)
示例#7
0
 def test_simple_case_2(self):
   expression = "1 + 2 - 3".split()
   expected = "1 2 + 3 -".split()
   actual = reverse_polish_notation(expression, operators, functions)
   self.assertEqual(actual, expected)