示例#1
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))
示例#2
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"))
    )
示例#3
0
def test__can_do_implicit_cast_in_inequality_comparison():
    assert Number(1) != -1
    assert 1 != Number(-1)
示例#4
0
def test__multiplying_by_zero_is_zero(x):
    assert 0 * x == Number(0)
    assert x * 0 == Number(0)

    assert 0 * (Number(1) * Number(2)) == Number(0)
    assert (Number(1) * Number(2)) * 0 == Number(0)

    assert 0 * (Number(1) + Number(2)) == Number(0)
    assert (Number(1) + Number(2)) * 0 == Number(0)
示例#5
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))
示例#6
0
def test__derivative_of_sum_is_sum_of_derivatives(x):
    assert differentiate(2 + x + 2 * x, x) == Number(3)
示例#7
0
def test__derivative_of_x_is_one(x):
    assert differentiate(x, x) == Number(1)
示例#8
0
def test__can_multiply_two_numbers():
    assert Number(2) * Number(3) == Number(6)
示例#9
0
def test__product_of_opposite_signs_should_be_positive():
    assert Number(-1) * Number(-2) == Number(2)
示例#10
0
def test__can_compare_numbers_for_equality():
    assert Number(1) == Number(1)
示例#11
0
def test__can_do_implicit_cast_in_simple_sums():
    assert 1 + Number(2) == Number(3)
    assert Number(1) + 2 == Number(3)
示例#12
0
def test__can_sum_multiple_numbers():
    assert Number(1) + Number(2) + Number(3) == Number(6)
示例#13
0
def test__sum_should_be_commutative():
    assert Number(1) + Number(2) == Number(2) + Number(1)
示例#14
0
def test__can_sum_two_numbers():
    assert Number(1) + Number(2) == Number(3)
示例#15
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))
示例#16
0
def test__product_of_different_signs_should_be_negative():
    assert Number(-1) * Number(2) == Number(-2)
示例#17
0
def test__derivative_of_constant_product_is_constant(x, y):
    assert differentiate(2 * x, x) == Number(2)
    assert differentiate(x * y, x) == y
示例#18
0
def test__product_should_be_commutative():
    assert Number(2) * Number(3) == Number(3) * Number(2)
示例#19
0
def test__derivative_of_constant_is_zero(x):
    assert differentiate(1, "x") == Number(0)
    assert differentiate("x", "y") == Number(0)
示例#20
0
def test__can_multiply_multiple_numbers():
    assert Number(2) * Number(3) * Number(4) == Number(24)
示例#21
0
def test__can_fold_numbers_in_product_regardless_of_position(x):
    assert 2 * x * 3 == Product(Number(6), Variable("x"))
示例#22
0
def test__can_do_implicit_cast_in_simple_products():
    assert 2 * Number(2) == Number(4)
    assert Number(2) * 2 == Number(4)
示例#23
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))
示例#24
0
def test__can_compare_numbers_for_inequality():
    assert Number(1) != Number(-1)
示例#25
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)))
示例#26
0
def test_can_fold_numbers_in_sum_regardless_of_position(x):
    assert 2 + x + 3 == Sum(Number(5), Variable("x"))
示例#27
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))
示例#28
0
def test__can_do_implicit_cast_in_equality_comparison():
    assert 1 == Number(1)
    assert Number(1) == 1