def test_CurveT_dfdx(X, Y, i): ''' pytest test case ''' s = CurveT(X, Y, i) with pytest.raises(OutOfDomain): s.dfdx(X[0] - 1e-5) with pytest.raises(OutOfDomain): s.dfdx(X[-1] + 1e-5) for j in range(len(X) - 1): xj = X[j] deri = (s.eval(xj + CurveT.DX) - s.eval(xj)) / CurveT.DX assert isCloseEnough(s.dfdx(xj), deri)
def test_dfdx(): testX = [1, 2, 3, 4, 5, 6, 7] testY = [1, 4, 9, 16, 25, 36, 49] a = CurveT(testX, testY, 2) assert (a.dfdx(2) == 4) #Fail due to floating point approximation
def test_CurveT_dfdx(): X = [0, 1] Y = [2, 0] s = CurveT(X, Y, 1) with pytest.raises(OutOfDomain): s.dfdx(-1.0) with pytest.raises(OutOfDomain): s.dfdx(2.0) assert abs(s.dfdx(0.0) - -2.0) < 1e-6 assert abs(s.dfdx(0.5) - -2.0) < 1e-6 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.dfdx(0.0) - 1.5005) < 1e-6 assert abs(s.dfdx(0.5) - 2.0005) < 1e-6