def test_exppoly_integrate_quadratic_dependency_check(t1, t2): with pytest.raises(RuntimeError): ExpPoly(t1)._integrate("t1") with pytest.raises(RuntimeError): ExpPoly(t1**3)._integrate("t1") with pytest.raises(RuntimeError): ExpPoly(t1)._integrate_half1("t1") with pytest.raises(RuntimeError): ExpPoly(t1**3)._integrate_half1("t1") with pytest.raises(RuntimeError): ExpPoly(t1 + t2**2)._integrate_half2("t1", "t2") with pytest.raises(RuntimeError): ExpPoly(t1**3 + t2**2)._integrate_half2("t1", "t2") with pytest.raises(RuntimeError): ExpPoly(t1**2 + t2)._integrate_half2("t1", "t2") with pytest.raises(RuntimeError): ExpPoly(t1**2 + t2**3)._integrate_half2("t1", "t2")
def ep2(t1, t2, t3): return ExpPoly(4 - t1**2 - 2 * t2**2 - 0.5 * t1 * t2 - 2 * t1 * t3 + 3 * t2)
def ep1(t1): return ExpPoly(4 - t1**2 - 0.5 * t1)
def test_exppoly_multiplication(t1, t2): assert ExpPoly(2, t1) * ExpPoly(3, t2) == ExpPoly(6, t1 + t2) assert ExpPoly(2, t1) * 2 == ExpPoly(4, t1) assert 2 * ExpPoly(2, t1) == ExpPoly(4, t1) assert -ExpPoly(2, t1) == ExpPoly(-2, t1)
def test_exppoly_integrate_quadratic_coefficient_check(t1, t2): with pytest.raises(RuntimeError): ExpPoly(t2 * t1**2).integrate("t1")
def test_exppoly_equality(t1, t2, t3): assert ExpPoly(2, t1) == ExpPoly(2, t1) assert ExpPoly(2, t1) != ExpPoly(2, t2) assert ExpPoly(1, t1) != ExpPoly(2, t1)
def test_exppoly_str(t1, t2): ep = ExpPoly(2, t1 + t2) assert str(ep) in {"2 * exp(1 * t1^1 + 1 * t2^1)", "2 * exp(1 * t2^1 + 1 * t1^1)"} assert str(ep) == repr(ep)
def test_exppoly_eval(t1, t2): assert ExpPoly(2, -((t1 - t2) ** 3)).eval(t1=2, t2=4) == 2 * np.exp(-((-2) ** 3))
def test_exppoly_substitute(t1, t2, t3): assert ExpPoly(2, -(t3**2)).substitute("t3", t1 - t2) == ExpPoly( 2, -(t1**2) + 2 * t1 * t2 - t2**2 )
def test_exppoly_constructor(t1): assert ExpPoly(t1) == ExpPoly(1, t1)