def main(): """Main Read - Eval - Print - Loop. """ while True: try: line = input("> ") print(evaluate(line)) except (SyntaxError, ValueError) as e: print(e) except EOFError: print() # Print empty line break
def test_log_precedence(): assert evaluate('log(1 + 1)') == evaluate('log(2)') == 0.69314718055994530942 assert evaluate('log 1 + 1') == 1.0
def test_evaluate_negative_number(): assert evaluate('-1') == -1.0
def test_evaluate_with_function(): assert evaluate('log 2') == evaluate('log(2)') == 0.69314718055994530942
def test_evaluate_complex_expression(): assert evaluate('3 + 4 * 2 / ( 1 - 5 )') == 1.0
def test_evaluate_simple_sum(): assert evaluate('1 + 2') == 3.0
def test_assert_simple_equation(): assert evaluate('2 * x = 1') == 'x = 0.5'
def test_solve_trivial_equation(): assert evaluate('x = 1') == 'x = 1.0'