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))
def test_CurveT_quadVal(): with open('tmp_file', 'w') as f: f.write('\n'.join( ['1.0, 5.0', '2.0, 20.0', '3.0, 25.0', '4.0, 40.0', '5.0, 41.0'])) try: curve = CurveT('tmp_file') assert (isClose(curve.quadVal(1.5), 13.75) and isClose(curve.quadVal(2.5), 23.75) and isClose(curve.quadVal(3.5), 31.25)) assert (isClose(curve.quadVal(1.01), 5.1995) and isClose(curve.quadVal(2.01), 20.0995) and isClose(curve.quadVal(3.01), 25.1005)) assert (isClose(curve.quadVal(1.99), 19.8995) and isClose(curve.quadVal(2.99), 24.9995) and isClose(curve.quadVal(3.99), 39.8005)) try: curve.quadVal(0.5) raise AssertionError except ValueError: pass try: curve.quadVal(5.5) raise AssertionError except ValueError: pass print('test of CurveT.quadVal PASSED.') except (AssertionError, ValueError, IndexError): print('test of CurveT.quadVal FAILED.') with open('tmp_file', 'w') as f: f.write('\n'.join(['1.0, 5.0', '2.0, 20.0'])) try: curve = CurveT('tmp_file') try: curve.quadVal(1.5) raise AssertionError except ValueError as e: pass print('test of CurveT.quadVal PASSED.') except (AssertionError, ValueError, IndexError): print('test of CurveT.quadVal FAILED.')