def test_CurveT_d2fdx2(X, Y, i): ''' pytest test case ''' s = CurveT(X, Y, i) with pytest.raises(OutOfDomain): s.d2fdx2(X[0] - 1e-5) with pytest.raises(OutOfDomain): s.d2fdx2(X[-1] + 1e-5) for j in range(len(X) - 1): xj = X[j] deri = (s.eval(xj + CurveT.DX * 2) - 2 * s.eval(xj + CurveT.DX) + s.eval(xj)) / (CurveT.DX**2) assert isCloseEnough(s.d2fdx2(xj), deri)
def test_df2dx2(): #End tests for CurveADT normal cases testX = [1, 2, 3, 4, 5, 6, 7] testY = [1, 4, 9, 16, 25, 36, 49] a = CurveT(testX, testY, 2) assert (a.d2fdx2(2) == 2) #Fail due to floating point approximation
def test_CurveT_d2fdx2(): X = [0, 1] Y = [2, 0] s = CurveT(X, Y, 1) with pytest.raises(OutOfDomain): s.d2fdx2(-1.0) with pytest.raises(OutOfDomain): s.d2fdx2(2.0) assert s.d2fdx2(0.0) == 0.0 assert s.d2fdx2(0.5) == 0.0 X = [-1, 0, 1] Y = [0, 1, 3] s = CurveT(X, Y, 2) with pytest.raises(OutOfDomain): s.eval(-2.0) with pytest.raises(OutOfDomain): s.eval(4.0) assert abs(s.d2fdx2(0.0) - 1.0) < 1e-6 assert abs(s.d2fdx2(0.5) - 1.0) < 1e-6