def test_evaluate_grouping(inputs, expected): expr = Expression(INT_A.in_([INT_B, INT_C * 2])) assert expr.evaluate(values(inputs)) == expected
def test_expression_inequality(): assert Expression(BOOL_A) != Expression(~BOOL_A)
def test_evaluate_bind_param_equals(): expr = Expression(INT_A == 5) assert not expr.evaluate(values({INT_A: 4})) assert expr.evaluate(values({INT_A: 5}))
def test_evaluate_bind_param_contains(): expr = Expression(INT_A.in_([1, 2, 3, 4, 5])) assert expr.evaluate(values({INT_A: 3})) assert not expr.evaluate(values({INT_A: 6}))
def test_bool_expr_negation(inputs, expected): expression = Expression(~BOOL_A) assert expression.evaluate(values(inputs)) == expected
def test_expression_self_equality(): expr = Expression(BOOL_A & (INT_A > 5)) assert expr == expr
def test_division(): expr = Expression(INT_A / INT_B) assert expr.evaluate(values({INT_A: 4, INT_B: 2})) == 2
def test_serlialize_unsupported_opeator(): with pytest.raises(TypeError, match="Unsupported operator"): Expression(INT_A.op("^")(INT_A))
def test_addition(): expr = Expression(INT_A + INT_B) assert expr.evaluate(values({INT_A: 2, INT_B: -10})) == -8
def test_subtraction(): expr = Expression(INT_A - INT_B) assert expr.evaluate(values({INT_A: 2, INT_B: 5})) == -3
def test_expression_equality(): expr = BOOL_A & (INT_A > 5) left = Expression(expr) right = Expression(expr) assert left is not right assert left == right
def test_bool_empty_clauselists(clause): expression = Expression(clause) assert expression.evaluate(values({}))
def test_bool_disjunction_clauselists(inputs, expected): expression = Expression(or_(BOOL_A, BOOL_B, BOOL_C)) assert expression.evaluate(values(inputs)) == expected
def test_expression_and_symbol_comparability(other): expr = Expression(BOOL_A & (INT_A > 5)) assert expr != other
def test_multiplication(): expr = Expression(INT_A * INT_B) assert expr.evaluate(values({INT_A: 4, INT_B: -3})) == -12
def test_serlialize_unsupported_expression(): with pytest.raises(TypeError, match="Unsupported expression"): Expression(func.exp(INT_A, 2))
def test_bitwise_inversion(): expr = Expression(~INT_A) assert expr.evaluate(values({INT_A: 127})) == -128 assert expr.evaluate(values({INT_A: -128})) == 127
def test_bool_expr_direct_column(inputs, expected): expression = Expression(BOOL_A) assert expression.evaluate(values(inputs)) == expected
def test_mixed_math(): expr = Expression((INT_A * INT_B) + (INT_A / INT_C)) assert expr.evaluate(values({INT_A: 8, INT_B: 2, INT_C: 4})) == 18
def test_bool_expr_conjunction(inputs, expected): expression = Expression(BOOL_A & BOOL_B) assert expression.evaluate(values(inputs)) == expected
def test_bool_expr_mixed(inputs, expected): expression = Expression((BOOL_A & ~BOOL_B) | BOOL_C) assert expression.evaluate(values(inputs)) == expected