Exemple #1
0
def test_error_invalid_token_with_whitespace():
    with pytest.raises(SyntaxError) as excinfo:
        tokenize('1 + lo g 2')
    assert ('SyntaxError: Invalid character "l"'
            in excinfo.exconly())
Exemple #2
0
def test_tokenize_single_int():
    assert tokenize("1") == tokenize("   1 ") == ["1"]
Exemple #3
0
def test_linear_equation():
    assert tokenize("2*x=1") == tokenize("  2 * x = 1") == ["2", "*", "x", "=", "1"]
Exemple #4
0
def test_error_on_invalid_character():
    with pytest.raises(SyntaxError) as excinfo:
        tokenize('1 + yxz')
    assert ('SyntaxError: Invalid character "y"'
            in excinfo.exconly())
Exemple #5
0
def test_tokenize_parentheses():
    assert tokenize("1*(2+3)") == tokenize("  1 * (2 + 3  )") == ["1", "*", "(", "2", "+", "3", ")"]
Exemple #6
0
def test_tokenize_log():
    assert tokenize("log(2.0)") == tokenize("  log ( 2.0  )") == ["log", "(", "2.0", ")"]
Exemple #7
0
def test_tokenize_binary_simple_operations():
    assert tokenize("1+2") == tokenize("1 +    2") == ["1", "+", "2"]
    assert tokenize("1-2") == tokenize("  1 - 2") == ["1", "-", "2"]
    assert tokenize("1*2") == tokenize("1   * 2  ") == ["1", "*", "2"]
    assert tokenize("1/2") == tokenize("1   / 2") == ["1", "/", "2"]
Exemple #8
0
def test_tokenize_unary():
    assert tokenize("-1") == tokenize("  -   1") == ["-", "1"]
Exemple #9
0
def test_tokenize_single_float():
    assert tokenize("1.0") == tokenize("   1.0  ") == ["1.0"]