Ejemplo n.º 1
0
def test_ast_minus_function(capsys):
    raw_formula = "{sin$1} - gravitational_constant"
    expected = ("FUNCTION", 'sin', ("NEGATIVE", 9.81))
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 2
0
def test_ast_subtraction_subtraction(capsys):
    raw_formula = "4 - 3 - 10"
    expected = ("MINUS",  ("MINUS", 4, 3), 10)
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 3
0
def test_ast_division(capsys):
    raw_formula = "50 / 10 / 5"
    expected = ("DIVIDE", ("DIVIDE", 50, 10), 5)
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 4
0
def test_ast_minus_function(capsys):
    raw_formula = "{sin$1} - {#pi}"
    expected = ("FUNCTION", 'sin', ("NEGATIVE", 'pi'))
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 5
0
def test_ast_functions_parenthesis(capsys):
    raw_formula = "{cos$1} (({cos$1} - {pi$0})*{pi$0})"
    expected = ("FUNCTION", 'cos', ("TIMES", ("FUNCTION", 'cos', ("NEGATIVE", 'pi')), pi))
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 6
0
def test_ast_factorial_complex(capsys):
    raw_formula = "-4!^3!"
    expected = -factorial(4) ** factorial(3)
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 7
0
def test_ast_empty(capsys):
    raw_formula = ""
    expected = ""
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 8
0
def test_ast_minus_negative(capsys):
    raw_formula = "40 - - 10"
    expected = ("MINUS", 40, ("NEGATIVE", 10))
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 9
0
def test_ast_parenthesis(capsys):
    raw_formula = "5 * (11 - 1)"
    expected = ("TIMES", 5, ("MINUS", 11, 1))
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 10
0
def test_ast_addition_negative(capsys):
    raw_formula = "40 + -10"
    expected = ("PLUS", 40 , ("NEGATIVE", 10))
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 11
0
def test_ast_number(capsys):
    raw_formula = '7'
    expected = 7
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 12
0
def test_ast_multiplication_negative(capsys):
    raw_formula = "4 * -10"
    expected = ("TIMES", 4, ("NEGATIVE", 10))
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 13
0
def test_ast_negative(capsys):
    raw_formula = "-10"
    expected = ("NEGATIVE",  10)
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 14
0
def test_ast_functions_parenthesis(capsys):
    raw_formula = "{cos$1} (({cos$1} - constant)*constant)"
    expected = ("FUNCTION", 'cos', ("TIMES", ("FUNCTION", 'cos', ("NEGATIVE", 1)), 1))
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 15
0
def test_ast_addition(capsys):
    raw_formula = "3 + 4"
    expected = ('PLUS', 3, 4)
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 16
0
def test_ast_parenthesis_whole(capsys):
    raw_formula = "(11 - 1)"
    expected = ("MINUS", 11 1)
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 17
0
def test_ast_factorial_factorial(capsys):
    raw_formula = "4!!"
    expected = factorial(factorial(4))
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 18
0
def test_ast_parenthesis_unary(capsys):
    raw_formula = "-(-1)"
    expected = 1
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 19
0
def test_ast_factorial_parenthesis(capsys):
    raw_formula = "(2 + 1)!"
    expected = 6
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 20
0
def test_ast_parenthesis_division(capsys):
    raw_formula = "1000/(90 + 10)"
    expected = 10
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 21
0
def test_ast_function(capsys):
    raw_formula = "{sin$1}(0)"
    expected = ("FUNCTION", 'sin', 0)
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 22
0
def test_ast_exponential(capsys):
    raw_formula = "2^5"
    expected = 2**5
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 23
0
def test_ast_function_1_function_1(capsys):
    raw_formula = "{cos$1} {sin$1} 0"
    expected = ("FUNCTION", 'cos', ("FUNCTION", 'sin', 0))
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 24
0
def test_ast_exponential_exponential(capsys):
    raw_formula = "3^3^2"
    expected = 3**9
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 25
0
def test_ast_ast_define_function_0(capsys):
    raw_formula = "{#hello} = 5"
    expected = ("ASSIGN", 'hello', 5)
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 26
0
def test_ast_exponential_exponential_multiplication(capsys):
    raw_formula = "3^3^2*2"
    expected = (3**9)*2
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 27
0
def test_ast_multiplication(capsys):
    raw_formula = "4 * 3 * 10"
    expected = ("TIMES", 4, 3, 10)
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 28
0
def test_ast_exponential_negative_exponential(capsys):
    raw_formula = "9^-2"
    expected = 3
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 29
0
def test_ast_division_multiplication(capsys):
    raw_formula = "50 / 10 * 5"
    expected = ("TIMES", ("DIVIDE", 50, 10), 5)
    check_parser(raw_formula, expected, capsys)
Ejemplo n.º 30
0
def test_ast_factorial_complex(capsys):
    raw_formula = "-4!^3!"
    expected = ("NEGATIVE", ("FACTORIAL", ("POWER", ("FACTORIAL", 4), 3)))
    check_parser(raw_formula, expected, capsys)