def x(): return Variable("x")
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_numeric_cast_in_sum_expressions(x): assert 1 + x == Sum(Number(1), Variable("x")) assert x + 1 == Sum(Variable("x"), Number(1))
def y(): return Variable("y")
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 "x" != Variable("y") assert Variable("y") != "x"
def test__can_compare_for_inequality(): assert Variable("x") != Variable("y")
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__can_multiply_two_distinct_variables(): assert Variable("x") * Variable("y") == Product(Variable("x"), Variable("y"))
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"))
def test__can_compare_for_equality(): assert Variable("x") == Variable("x")
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"))
def test__can_sum_two_distinct_variables(): assert Variable("x") + Variable("y") == Sum(Variable("x"), Variable("y"))
def test__multiplying_by_one_is_no_op(x): assert 1 * x == Variable("x") assert x * 1 == Variable("x")
def test_can_fold_numbers_in_sum_regardless_of_position(x): assert 2 + x + 3 == Sum(Number(5), Variable("x"))
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__adding_zero_is_no_op(x): assert 0 + x == Variable("x") assert x + 0 == Variable("x")
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_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_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 "x" == Variable("x") assert Variable("x") == "x"