示例#1
0
def test_calls_operators_with_correct_arguments():
    operators = {
        "+": Mock(wraps=operator.add),
        "*": Mock(wraps=operator.mul),
        "-": Mock(wraps=operator.sub)
    }

    evaluate_rpn([5, 4, 1, "-", "*", 2, "+"], operators)

    operators["-"].assert_called_once_with(4, 1)
    operators["*"].assert_called_once_with(5, 3)
    operators["+"].assert_called_once_with(15, 2)
示例#2
0
def test_computes_correct_value():
    assert evaluate_rpn([5, 4, 1, "-", "*", 2, "+"], OPERATORS) == 17
示例#3
0
 def test_addition_of_two_numbers(self):
     self.assertEqual(evaluate_rpn('4 7 +'), 11)
示例#4
0
 def test_subtraction_of_two_numbers(self):
     self.assertEqual(evaluate_rpn('7 4 -'), 3)
示例#5
0
 def test_multiplication_and_negation_of_two_numbers(self):
     self.assertEqual(evaluate_rpn('5 8 * n p'), -40)
示例#6
0
 def test_addition_and_exponential_power_raise_of_three_numbers(self):
     self.assertEqual(evaluate_rpn('3 6 1 + + 2 e p'), 100)
示例#7
0
 def test_addition_of_three_numbers(self):
     self.assertEqual(evaluate_rpn('4 7 3 + + p'), 14)
示例#8
0
 def test_exponential_of_two_numbers(self):
     self.assertEqual(evaluate_rpn('6 2 e'), 36)
示例#9
0
 def test_negation_of_a_number(self):
     self.assertEqual(evaluate_rpn('40 n'), -40)
示例#10
0
 def test_floor_division_of_two_numbers(self):
     self.assertEqual(evaluate_rpn('5 2 //'), 2)
示例#11
0
 def test_multiplication_of_two_numbers(self):
     self.assertEqual(evaluate_rpn('5 8  *'), 40)