Ejemplo n.º 1
0
def test_CurveT_linVal():
    with open('tmp_file', 'w') as f:
        f.write('\n'.join(
            ['1.0, 10.0', '2.0, 20.0', '3.0, 30.0', '4.0, 40.0', '5.0, 50.0']))
    try:
        curve = CurveT('tmp_file')
        assert (isClose(curve.linVal(1.5), 15.0)
                and isClose(curve.linVal(2.5), 25.0)
                and isClose(curve.linVal(3.5), 35.0))
        assert (isClose(curve.linVal(1.001), 10.01)
                and isClose(curve.linVal(2.001), 20.01)
                and isClose(curve.linVal(3.001), 30.01))
        assert (isClose(curve.linVal(1.999), 19.99)
                and isClose(curve.linVal(2.999), 29.99)
                and isClose(curve.linVal(3.999), 39.99))
        try:
            curve.linVal(0.5)
            raise AssertionError
        except ValueError:
            pass
        try:
            curve.linVal(5.5)
            raise AssertionError
        except ValueError:
            pass
        print('test of CurveT.linVal PASSED.')
    except (AssertionError, ValueError, IndexError):
        print('test of CurveT.linVal FAILED.')
Ejemplo n.º 2
0
def testCurveADT():
    testQuad = CurveT()
    quadVal_T = "testQuad.txt"
    if quadVal_T == None:
        raise LookupError("Cannot find file 'testQuad.txt'")
        exit()

    testLin = CurveT()
    linVal_T = "testLin.txt"
    if linVal_T == None:
        raise LookupError("Cannot find file 'testLin.txt'")
        exit()

    testnPoly = CurveT()
    nPolyVal_T = "testnplyv.txt"
    if nPolyVal_T == None:
        raise LookupError("Cannot find file 'testnplyv.txt'")
        exit()

    testQuad.CurveT(quadVal_T)
    testnPoly.CurveT(nPolyVal_T)
    testLin.CurveT(linVal_T)


    count = 0

    x_Lin = 8
    linVal = testLin.linVal(x_Lin)
    if (linVal == 16):
        print("linVal: Pass")
        count+=1
    else:
        print("linVal: Failed")

    x_Quad = 5
    quadVal = testQuad.quadVal(x_Quad)

    if(quadVal == 25):
        print("quadVal: Pass")
        count+=1
    else:
        print("quadVal: Failed")

    n_Poly = 3
    x_Poly = 5.5
    nPolyVal = testnPoly.npolyval(n_Poly,x_Poly)
    if(round(nPolyVal,3) == 166.375):
        print("nPolyVal: Pass")
        count+=1
    else:

        print("nPolyVal: Failed")

    if(count == 3):
        print("\n{} of 3 passed\nCurveADT is good to go!".format(count))
    else:
        print("\n{} of 3 passed\nCurveADT is no good :( Try fixing it!".format(count))
Ejemplo n.º 3
0
def program():
    testCurve = CurveT()

    testCurve.CurveT('input.txt')
    n = input("Enter the order of polynomial function: ")
    x = input("Enter x value you wish to know y value for: ")

    if (n == 1):
        linTest = testCurve.linVal(x)
        print("linVal: {}".format(linTest))
    elif (n == 2):
        polyTest = testCurve.quadVal(x)
        print("polyVal results : {}".format(polyTest))
    else:
        y = testCurve.npolyval(n, x)
        print("The y value of %f is %f" % (x, y))
Ejemplo n.º 4
0
def main():
    newCurve = CurveT()

    #filename = raw_input("What is the name of the file?: ")
    filename = "linear.txt"
    newCurve.CurveT(filename)
    #xVal = input("What value of x would you like to find the y-value for?: ")
    xVal = newCurve.curveX.

    if (newCurve.degree == 1):
        linTest = newCurve.linVal(xVal)
        print("linval: %f" % linTest)
    elif (newCurve.degree == 2):
        polyTest = newCurve.quadVal(xVal)
        print("polyval: %f" % polyTest)

    yVal = newCurve.npolyval(xVal)

    print("The y value of %f is %f" % (xVal, yVal))