|
| 1 | +"""Mixed column conditions use AND precedence over OR.""" |
| 2 | + |
| 3 | +import itertools |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from apps.api.services.workbook.conditions import evaluate_condition |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.parametrize("a,b,c", list(itertools.product([False, True], repeat=3))) |
| 11 | +@pytest.mark.parametrize("expression,order", [ |
| 12 | + ('{a} == "yes" OR {b} == "yes" AND {c} == "yes"', "or-and"), |
| 13 | + ('{a} == "yes" AND {b} == "yes" OR {c} == "yes"', "and-or"), |
| 14 | +]) |
| 15 | +def test_mixed_conditions_follow_boolean_truth_table(a, b, c, expression, order): |
| 16 | + cells = {key: {"value": "yes" if value else "no"} for key, value in zip("abc", (a, b, c))} |
| 17 | + expected = (a or (b and c)) if order == "or-and" else ((a and b) or c) |
| 18 | + assert evaluate_condition(expression, cells, []) is expected |
| 19 | + |
| 20 | + |
| 21 | +def test_mixed_conditions_keep_operator_text_inside_literals_and_cells(): |
| 22 | + cells = {"name": {"value": "Sales OR Marketing AND Research"}, "score": {"value": 10}} |
| 23 | + assert evaluate_condition( |
| 24 | + '{name} == "Sales OR Marketing AND Research" OR {score} > 20 AND {score} < 0', cells, [] |
| 25 | + ) |
| 26 | + assert not evaluate_condition( |
| 27 | + '{name} == "Other" OR {score} > 20 AND {name} == "Sales OR Marketing AND Research"', cells, [] |
| 28 | + ) |
0 commit comments