def test_gt_2(): ast = gt(div(add(c(1), c(2)), c(3)), add(c(1), c(2))) parser = Parser(Tokenizer("(1+2)/3 > 1 + 2")) assert parser.expression() == ast
def test_lt_1(): ast = lt(div(add(c(1), c(2)), c(3)), add(c(4), c(5))) parser = Parser(Tokenizer("(1+2)/3 < 4 + 5")) assert parser.expression() == ast
def test_parens(): ast = div(add(c(1), v("b")), c(4)) parser = Parser(Tokenizer("(1+b)/4")) assert parser.expression() == ast
def test_differing_priority_bins_2(): ast = add(div(c(1), v("b")), c(4)) parser = Parser(Tokenizer("1/b+4")) assert parser.expression() == ast
def test_differing_priority_bins_1(): ast = add(c(1), div(v("b"), c(4))) parser = Parser(Tokenizer("1+b/4")) assert parser.expression() == ast
]) def test_binary_ops_level_5_and_below(op, left, right, op_str, left_str, right_str): ast = op(left, right) s = left_str + op_str + right_str parser = Parser(Tokenizer(s)) assert parser.expression() == ast @pytest.mark.parametrize("op, op_str", [ (add, "+"), (sub, "-"), ]) @pytest.mark.parametrize("left, left_str", [ (c(1), "1"), (div(c(1), c(3)), "1/3"), (sub(c(1)), "-1"), (v("a"), "a"), ]) @pytest.mark.parametrize("right, right_str", [ (c(2), "2"), (div(c(2), c(4)), "2/4"), (sub(c(2)), "-2"), (v("b"), "b"), ]) def test_binary_ops_level_4_and_below(op, left, right, op_str, left_str, right_str): ast = op(left, right) s = left_str + op_str + right_str parser = Parser(Tokenizer(s)) assert parser.expression() == ast