예제 #1
0
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)
예제 #2
0
def test_Data_slice(X, Y, i):
    ''' pytest test case
    '''
    Data.init()
    Data_Z = []
    Data_S = []
    z = X[0]
    for z in np.linspace(X[0], X[-1], Data.MAX_SIZE):
        Data_Z.append(z)
        s = CurveT(X, Y, i)
        Data_S.append(s)
        Data.add(s, z)
        for k in range(len(X)):
            Y[k] += 1

    for i in range(len(X) - 1):
        xi = X[i]
        xi1 = X[i + 1]
        for x in (xi, (xi + xi1) / 2):
            Data_Y = []
            for j in range(len(Data_S)):
                s = Data_S[j]
                y = s.eval(x)
                Data_Y.append(y)
            s1 = Data.slice(x, 1)
            s2 = CurveT(Data_Z, Data_Y, 1)
            assert isSame(s1, s2)
예제 #3
0
def test_CurveEval():

    testX = [1, 2, 3, 4, 5, 6, 7]
    testY = [1, 4, 9, 16, 25, 36, 49]

    a = CurveT(testX, testY, 2)

    assert (a.eval(2) == 4)  #Fail due to floating point approximation
예제 #4
0
def test_CurveT_eval(X, Y, i):
    ''' pytest test case
    '''
    s = CurveT(X, Y, i)

    with pytest.raises(OutOfDomain):
        s.eval(X[0] - 1e-5)
    with pytest.raises(OutOfDomain):
        s.eval(X[-1] + 1e-5)

    o = i

    for i in range(len(X) - 1):
        xi = X[i]
        yi = Y[i]
        if o == 1 or i > 0:
            assert isCloseEnough(s.eval(xi), yi)
        xi1 = X[i + 1]
        if o == 1:
            f = interpolate.interp1d(X[i:i + 2], Y[i:i + 2], kind='linear')
            assert isCloseEnough(s.eval((xi + xi1) / 2), f((xi + xi1) / 2))
        else:
            if i == 0:
                f = interpolate.interp1d(X[i:i + 3],
                                         Y[i:i + 3],
                                         kind='quadratic')
            else:
                f = interpolate.interp1d(X[i - 1:i + 2],
                                         Y[i - 1:i + 2],
                                         kind='quadratic')
            assert isCloseEnough(s.eval((xi + xi1) / 2), f((xi + xi1) / 2))
예제 #5
0
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
예제 #6
0
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
예제 #7
0
def test_CurveT_eval():
    X = [0, 1]
    Y = [2, 0]
    s = CurveT(X, Y, 1)
    with pytest.raises(OutOfDomain):
        s.eval(-1.0)
    with pytest.raises(OutOfDomain):
        s.eval(2.0)
    assert s.eval(0.0) == 2.0
    assert s.eval(0.5) == 1.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 s.eval(-0.5) == 0.375
    assert s.eval(0.0) == 1.0
    assert s.eval(0.5) == 1.875