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))
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))
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))