示例#1
0
def test_evaluate_grouping(inputs, expected):
    expr = Expression(INT_A.in_([INT_B, INT_C * 2]))
    assert expr.evaluate(values(inputs)) == expected
示例#2
0
def test_expression_inequality():
    assert Expression(BOOL_A) != Expression(~BOOL_A)
示例#3
0
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}))
示例#4
0
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}))
示例#5
0
def test_bool_expr_negation(inputs, expected):
    expression = Expression(~BOOL_A)
    assert expression.evaluate(values(inputs)) == expected
示例#6
0
def test_expression_self_equality():
    expr = Expression(BOOL_A & (INT_A > 5))
    assert expr == expr
示例#7
0
def test_division():
    expr = Expression(INT_A / INT_B)
    assert expr.evaluate(values({INT_A: 4, INT_B: 2})) == 2
示例#8
0
def test_serlialize_unsupported_opeator():
    with pytest.raises(TypeError, match="Unsupported operator"):
        Expression(INT_A.op("^")(INT_A))
示例#9
0
def test_addition():
    expr = Expression(INT_A + INT_B)
    assert expr.evaluate(values({INT_A: 2, INT_B: -10})) == -8
示例#10
0
def test_subtraction():
    expr = Expression(INT_A - INT_B)
    assert expr.evaluate(values({INT_A: 2, INT_B: 5})) == -3
示例#11
0
def test_expression_equality():
    expr = BOOL_A & (INT_A > 5)
    left = Expression(expr)
    right = Expression(expr)
    assert left is not right
    assert left == right
示例#12
0
def test_bool_empty_clauselists(clause):
    expression = Expression(clause)
    assert expression.evaluate(values({}))
示例#13
0
def test_bool_disjunction_clauselists(inputs, expected):
    expression = Expression(or_(BOOL_A, BOOL_B, BOOL_C))
    assert expression.evaluate(values(inputs)) == expected
示例#14
0
def test_expression_and_symbol_comparability(other):
    expr = Expression(BOOL_A & (INT_A > 5))
    assert expr != other
示例#15
0
def test_multiplication():
    expr = Expression(INT_A * INT_B)
    assert expr.evaluate(values({INT_A: 4, INT_B: -3})) == -12
示例#16
0
def test_serlialize_unsupported_expression():
    with pytest.raises(TypeError, match="Unsupported expression"):
        Expression(func.exp(INT_A, 2))
示例#17
0
def test_bitwise_inversion():
    expr = Expression(~INT_A)
    assert expr.evaluate(values({INT_A: 127})) == -128
    assert expr.evaluate(values({INT_A: -128})) == 127
示例#18
0
def test_bool_expr_direct_column(inputs, expected):
    expression = Expression(BOOL_A)
    assert expression.evaluate(values(inputs)) == expected
示例#19
0
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
示例#20
0
def test_bool_expr_conjunction(inputs, expected):
    expression = Expression(BOOL_A & BOOL_B)
    assert expression.evaluate(values(inputs)) == expected
示例#21
0
def test_bool_expr_mixed(inputs, expected):
    expression = Expression((BOOL_A & ~BOOL_B) | BOOL_C)
    assert expression.evaluate(values(inputs)) == expected