def test_evaluate_valid_expressions(): #Testing the positive Test cases test_io_cases = { "1 2 3 + -": -4, "6 2 * 3 /": 4, "2 3 ^ 4 5 + +": 17, "50 % 2 *": 1, "3 ! 4 5 * +": 26, "12 3 / !": 24, "5 1 2 + 4 * + 3 -": 14, } for expression, expected_output in test_io_cases.iteritems(): actual_op = RPN.evaluate_expression(expression) print "Output is %s for %s" % (expected_output, expression) assert actual_op == expected_output
def main(): # Display Help in the beginning of the program. print RPN.rpn_help() # Get into a controlled Daemon/infinite loop. while True: # Get the RPN expression input_text = RPN.get_input() # Check what have you got, if its an expression, call for evaluation if RPN.is_expression(input_text): output = RPN.evaluate_expression(input_text) print output
def test_evaluate_invalid_expressions(): #Testing the Negative Test cases test_io_cases = { "2 +": "error : Not enough Operands to proceed with binary operation", "6sad": "error : Not a Valid RPN, try until you succeed...e.g. 2 3 +", "2 3 4 +": "error : Not a Valid RPN, try until you succeed...e.g. 2 3 +", "-6": "error : Not a Valid RPN, try until you succeed...e.g. 2 3 +", "!": "error : Not enough Operands to proceed with unary operation", "%": "error : Not enough Operands to proceed with unary operation" } for expression, expected_output in test_io_cases.iteritems(): actual_op = RPN.evaluate_expression(expression) print "Output is %s for %s" % (expected_output, expression) assert actual_op == expected_output