def test_trig_func_class_stuff(): for name, func in [('sin', sin), ('cos', cos), ('tan', tan)]: assert func(2 * x).arg == 2 * x with pytest.raises(TypeError): func(x, y) assert repr(func(x)) == name + '(x)' assert func(f(x)).replace(f(x), y) == func(y) # test apply_to_content assert func(x).pow_parenthesize() == '(%s(x))' % name
def test_trig_derivatives(): assert sin(x).derivative(x) == cos(x) assert cos(x).derivative(x) == -sin(x) assert tan(x).derivative(x) == 1 + tan(x)**2 assert sin(f(x)).derivative(x) == cos(f(x)) * f_(x) assert cos(f(x)).derivative(x) == -sin(f(x)) * f_(x) assert tan(f(x)).derivative(x) == f_(x) + f_(x) * tan(f(x))**2
def test_eqs_and_hashes(hasheq): assert hasheq(x, x) assert not hasheq(x, y) assert hasheq(f(x), f(x)) assert hasheq(f_(x), f_(x)) assert not hasheq(f(x), f(y)) assert not hasheq(f(x), f_(x)) assert not hasheq(f(x), g(x))
def test_derivatives(): with pytest.raises(ValueError, match="negative derivative_count is not supported$"): f(x, derivative_count=-1) assert x.derivative(x) == mathify(1) assert x.derivative(y) == mathify(0) assert f(x).derivative(x) == f_(x) assert f(x).derivative(x).derivative(x) == f__(x) assert f(x).derivative(y) == mathify(0) assert f( g(x)).derivative(x) == f_(g(x)) * g_(x), "u forgot chain rule n00b"
def test_derivatives(): assert (f(x) + g(x) + h(x)).derivative(x) == f_(x) + g_(x) + h_(x) assert (f(x) * g(x) * h(x)).derivative(x) == (f_(x) * g(x) * h(x) + f(x) * g_(x) * h(x) + f(x) * g(x) * h_(x)) assert (f(x)**g(x)).derivative(x) == ( f(x)**g(x) * (g_(x) * ln(f(x)) + g(x) * f_(x) / f(x))) assert (f(x)**a).derivative(x) == a * f(x)**(a - 1) * f_(x) assert (a**f(x)).derivative(x) == a**f(x) * ln(a) * f_(x)
def test_reprs(): assert repr(x) == 'x' assert repr(f(x)) == 'f(x)' assert repr(f(x, derivative_count=2)) == "f''(x)"
def test_automagic_mathify(): assert f(2).arg == mathify(2)
def test_may_depend_on(): assert x.may_depend_on(x) assert not x.may_depend_on(y) assert f(x).may_depend_on(x) assert not f(x).may_depend_on(y)