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))
def test__can_multiply_products_and_sums(x): assert (x + 1) * (2 + x) == Product( Sum(Number(1), Variable("x")), Sum(Number(2), Variable("x")) )
def test__can_do_implicit_cast_in_inequality_comparison(): assert Number(1) != -1 assert 1 != Number(-1)
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)
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))
def test__derivative_of_sum_is_sum_of_derivatives(x): assert differentiate(2 + x + 2 * x, x) == Number(3)
def test__derivative_of_x_is_one(x): assert differentiate(x, x) == Number(1)
def test__can_multiply_two_numbers(): assert Number(2) * Number(3) == Number(6)
def test__product_of_opposite_signs_should_be_positive(): assert Number(-1) * Number(-2) == Number(2)
def test__can_compare_numbers_for_equality(): assert Number(1) == Number(1)
def test__can_do_implicit_cast_in_simple_sums(): assert 1 + Number(2) == Number(3) assert Number(1) + 2 == Number(3)
def test__can_sum_multiple_numbers(): assert Number(1) + Number(2) + Number(3) == Number(6)
def test__sum_should_be_commutative(): assert Number(1) + Number(2) == Number(2) + Number(1)
def test__can_sum_two_numbers(): assert Number(1) + Number(2) == Number(3)
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))
def test__product_of_different_signs_should_be_negative(): assert Number(-1) * Number(2) == Number(-2)
def test__derivative_of_constant_product_is_constant(x, y): assert differentiate(2 * x, x) == Number(2) assert differentiate(x * y, x) == y
def test__product_should_be_commutative(): assert Number(2) * Number(3) == Number(3) * Number(2)
def test__derivative_of_constant_is_zero(x): assert differentiate(1, "x") == Number(0) assert differentiate("x", "y") == Number(0)
def test__can_multiply_multiple_numbers(): assert Number(2) * Number(3) * Number(4) == Number(24)
def test__can_fold_numbers_in_product_regardless_of_position(x): assert 2 * x * 3 == Product(Number(6), Variable("x"))
def test__can_do_implicit_cast_in_simple_products(): assert 2 * Number(2) == Number(4) assert Number(2) * 2 == Number(4)
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))
def test__can_compare_numbers_for_inequality(): assert Number(1) != Number(-1)
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)))
def test_can_fold_numbers_in_sum_regardless_of_position(x): assert 2 + x + 3 == Sum(Number(5), Variable("x"))
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))
def test__can_do_implicit_cast_in_equality_comparison(): assert 1 == Number(1) assert Number(1) == 1