Пример #1
0
def x():
    return Variable("x")
Пример #2
0
def test__can_fold_numbers_in_product_regardless_of_position(x):
    assert 2 * x * 3 == Product(Number(6), Variable("x"))
Пример #3
0
def test__can_do_implicit_numeric_cast_in_sum_expressions(x):
    assert 1 + x == Sum(Number(1), Variable("x"))
    assert x + 1 == Sum(Variable("x"), Number(1))
Пример #4
0
def y():
    return Variable("y")
Пример #5
0
def test__can_multiply_products_and_sums(x):
    assert (x + 1) * (2 + x) == Product(
        Sum(Number(1), Variable("x")), Sum(Number(2), Variable("x"))
    )
Пример #6
0
def test__can_do_implicit_cast_in_inequality_comparison():
    assert "x" != Variable("y")
    assert Variable("y") != "x"
Пример #7
0
def test__can_compare_for_inequality():
    assert Variable("x") != Variable("y")
Пример #8
0
def test__can_multiply_numbers_and_variables(x):
    assert Number(2) * x == Product(Number(2), Variable("x"))
    assert x * Number(2) == Product(Variable("x"), Number(2))
Пример #9
0
def test__can_multiply_two_distinct_variables():
    assert Variable("x") * Variable("y") == Product(Variable("x"),
                                                    Variable("y"))
Пример #10
0
def test__can_multiply_two_variables_with_implicit_cast():
    assert "x" * Variable("x") == Product(Variable("x"), Variable("x"))
    assert Variable("x") * "x" == Product(Variable("x"), Variable("x"))
Пример #11
0
def test__can_compare_for_equality():
    assert Variable("x") == Variable("x")
Пример #12
0
def test__can_sum_two_variables_with_implicit_cast():
    assert Variable("x") + "x" == Sum(Variable("x"), Variable("x"))
    assert "x" + Variable("x") == Sum(Variable("x"), Variable("x"))
Пример #13
0
def test__can_sum_two_distinct_variables():
    assert Variable("x") + Variable("y") == Sum(Variable("x"), Variable("y"))
Пример #14
0
def test__multiplying_by_one_is_no_op(x):
    assert 1 * x == Variable("x")
    assert x * 1 == Variable("x")
Пример #15
0
def test_can_fold_numbers_in_sum_regardless_of_position(x):
    assert 2 + x + 3 == Sum(Number(5), Variable("x"))
Пример #16
0
def test__can_multiply_numbers_and_products(x):
    assert 2 * (x * 1) == Product(Variable("x"), Number(2))
    assert (x * 1) * 2 == Product(Variable("x"), Number(2))
Пример #17
0
def test__adding_zero_is_no_op(x):
    assert 0 + x == Variable("x")
    assert x + 0 == Variable("x")
Пример #18
0
def test__can_multiply_numbers_and_sums(x):
    assert 2 * (x + 1) == Product(Number(2), Sum(Variable("x"), Number(1)))
    assert (x + 1) * 2 == Product(Number(2), Sum(Variable("x"), Number(1)))
Пример #19
0
def test__can_sum_numbers_and_variables(x):
    assert Number(1) + x == Sum(Number(1), Variable("x"))
    assert x + Number(1) == Sum(Variable("x"), Number(1))
Пример #20
0
def test__can_do_implicit_numeric_cast_in_product_expressions(x):
    assert 2 * x == Product(Number(2), Variable("x"))
    assert x * 2 == Product(Variable("x"), Number(2))
Пример #21
0
def test__can_do_implicit_cast_in_equality_comparison():
    assert "x" == Variable("x")
    assert Variable("x") == "x"