Beispiel #1
0
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
Beispiel #2
0
def test_log_precedence():
    assert evaluate('log(1 + 1)') == evaluate('log(2)') == 0.69314718055994530942
    assert evaluate('log 1 + 1') == 1.0
Beispiel #3
0
def test_evaluate_negative_number():
    assert evaluate('-1') == -1.0
Beispiel #4
0
def test_evaluate_with_function():
    assert evaluate('log 2') == evaluate('log(2)') == 0.69314718055994530942
Beispiel #5
0
def test_evaluate_complex_expression():
    assert evaluate('3 + 4 * 2 / ( 1 - 5 )') == 1.0
Beispiel #6
0
def test_evaluate_simple_sum():
    assert evaluate('1 + 2') == 3.0
Beispiel #7
0
def test_assert_simple_equation():
    assert evaluate('2 * x = 1') == 'x = 0.5'
Beispiel #8
0
def test_solve_trivial_equation():
    assert evaluate('x = 1') == 'x = 1.0'