Пример #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())
Пример #2
0
def test_tokenize_single_int():
    assert tokenize("1") == tokenize("   1 ") == ["1"]
Пример #3
0
def test_linear_equation():
    assert tokenize("2*x=1") == tokenize("  2 * x = 1") == ["2", "*", "x", "=", "1"]
Пример #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())
Пример #5
0
def test_tokenize_parentheses():
    assert tokenize("1*(2+3)") == tokenize("  1 * (2 + 3  )") == ["1", "*", "(", "2", "+", "3", ")"]
Пример #6
0
def test_tokenize_log():
    assert tokenize("log(2.0)") == tokenize("  log ( 2.0  )") == ["log", "(", "2.0", ")"]
Пример #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"]
Пример #8
0
def test_tokenize_unary():
    assert tokenize("-1") == tokenize("  -   1") == ["-", "1"]
Пример #9
0
def test_tokenize_single_float():
    assert tokenize("1.0") == tokenize("   1.0  ") == ["1.0"]