/* **** This test is designed to test the validity of the reset member of the PolyFit class **** Reset is tested by first adding data to a blank PolyFit object and then clearing **** that data (Please note this dad was already tested in the previous test) **** Please note isSingular, Solution, Degreem N and Solve were tested inderectly here */ void xPolyFit :: resetTest (void) { //Polynomial will be reset without user inputed parameter gpstk::PolyFit<double> resetPolyD(2); //Poly will be reset with a parameter gpstk::PolyFit<double> resetPolyP(2); double data[4] = {0.,2.,4.,-1.}; double time[4] = {3.,3.,4.,2.,}; for (int i =0;i<4;i++) { resetPolyD.Add(time[i],data[i]); resetPolyP.Add(time[i],data[i]); } resetPolyD.Reset(); gpstk::Matrix<double> Blank(2,2,0.); gpstk::Vector<double> Zero(2,0.); gpstk::Vector<double> resetPolyDSolution = resetPolyD.Solution(); gpstk::Matrix<double> resetPolyDCov = resetPolyD.Covariance(); CPPUNIT_ASSERT_EQUAL((unsigned) 0, resetPolyD.N()); CPPUNIT_ASSERT_EQUAL((unsigned) 2, resetPolyD.Degree()); CPPUNIT_ASSERT_EQUAL(true, resetPolyD.isSingular()); CPPUNIT_ASSERT_EQUAL(Blank[0][0],resetPolyDCov[0][0]); CPPUNIT_ASSERT_EQUAL(Blank[0][1],resetPolyDCov[0][1]); CPPUNIT_ASSERT_EQUAL(Blank[1][0],resetPolyDCov[1][0]); CPPUNIT_ASSERT_EQUAL(Blank[1][1],resetPolyDCov[1][1]); CPPUNIT_ASSERT_DOUBLES_EQUAL(Zero[0],resetPolyDSolution[0],1e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(Zero[1],resetPolyDSolution[1],1e-6); resetPolyP.Reset((unsigned) 3); gpstk::Matrix<double> BlankP(3,3,0.); gpstk::Vector<double> ZeroP(3,0.); gpstk::Vector<double> resetPolyPSolution = resetPolyP.Solution(); gpstk::Matrix<double> resetPolyPCov = resetPolyP.Covariance(); CPPUNIT_ASSERT_EQUAL((unsigned) 0, resetPolyP.N()); CPPUNIT_ASSERT_EQUAL((unsigned) 3, resetPolyP.Degree()); CPPUNIT_ASSERT_EQUAL(true, resetPolyP.isSingular()); CPPUNIT_ASSERT_EQUAL(BlankP[0][0],resetPolyPCov[0][0]); CPPUNIT_ASSERT_EQUAL(BlankP[0][1],resetPolyPCov[0][1]); CPPUNIT_ASSERT_EQUAL(BlankP[0][2],resetPolyPCov[0][2]); CPPUNIT_ASSERT_EQUAL(BlankP[1][0],resetPolyPCov[1][0]); CPPUNIT_ASSERT_EQUAL(BlankP[1][1],resetPolyPCov[1][1]); CPPUNIT_ASSERT_EQUAL(BlankP[1][2],resetPolyPCov[1][2]); CPPUNIT_ASSERT_EQUAL(BlankP[2][0],resetPolyPCov[2][0]); CPPUNIT_ASSERT_EQUAL(BlankP[2][1],resetPolyPCov[2][1]); CPPUNIT_ASSERT_EQUAL(BlankP[2][2],resetPolyPCov[2][2]); CPPUNIT_ASSERT_DOUBLES_EQUAL(ZeroP[0],resetPolyPSolution[0],1e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(ZeroP[1],resetPolyPSolution[1],1e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(ZeroP[2],resetPolyPSolution[2],1e-6); }
// Please note isSingular, Solution, Degreem N and Solve were tested inderectly here //========================================================================================================================== int resetTest(void) { TestUtil testFramework( "PolyFit", "Reset", __FILE__, __LINE__ ); bool covMatDiffBool = true; bool solnDiffBool = true; //Polynomial will be reset without user inputed parameter gpstk::PolyFit<double> resetPolyD(2); //Poly will be reset with a parameter gpstk::PolyFit<double> resetPolyP(2); double data[4] = {0.,2.,4.,-1.}; double time[4] = {3.,3.,4.,2.,}; for (int i =0;i<4;i++) { resetPolyD.Add(time[i],data[i]); resetPolyP.Add(time[i],data[i]); } //--------------------------------------------------------------------- //Test Reset() //--------------------------------------------------------------------- resetPolyD.Reset(); gpstk::Matrix<double> Blank(2,2,0.); gpstk::Vector<double> Zero(2,0.); gpstk::Vector<double> resetPolyDSolution = resetPolyD.Solution(); gpstk::Matrix<double> resetPolyDCov = resetPolyD.Covariance(); testFramework.assert((unsigned) 0 == resetPolyD.N() , "Reset did not set the datapoint counter to zero" , __LINE__); testFramework.assert((unsigned) 2 == resetPolyD.Degree(), "Reset did not maintain the maximum fit degree as 2", __LINE__); testFramework.assert(resetPolyD.isSingular() , "The fit found after Reset was not singular" , __LINE__); for (int i = 0; i<2; i++) { for (int j = 0; j<2; j++) { covMatDiffBool = covMatDiffBool && (Blank[i][j] == resetPolyDCov[i][j]); } solnDiffBool = solnDiffBool && (fabs(resetPolyDSolution[i]) < eps); } testFramework.assert(covMatDiffBool, "Covariance matrix found to be nonzero after Reset", __LINE__); testFramework.assert(solnDiffBool , "Solution vector found to be nonzero after Reset" , __LINE__); //--------------------------------------------------------------------- //Test Reset(int) //--------------------------------------------------------------------- resetPolyP.Reset((unsigned) 3); covMatDiffBool = true; solnDiffBool = true; gpstk::Matrix<double> BlankP(3,3,0.); gpstk::Vector<double> ZeroP(3,0.); gpstk::Vector<double> resetPolyPSolution = resetPolyP.Solution(); gpstk::Matrix<double> resetPolyPCov = resetPolyP.Covariance(); testFramework.assert((unsigned) 0 == resetPolyP.N() , "Reset(int) did not set the datapoint counter to zero" , __LINE__); testFramework.assert((unsigned) 3 == resetPolyP.Degree(), "Reset(int) did not change the maximum fit degree to 3", __LINE__); testFramework.assert(resetPolyP.isSingular() , "The fit found after Reset(int) was not singular" , __LINE__); for (int i = 0; i<3; i++) { for (int j = 0; j<3; j++) { covMatDiffBool = covMatDiffBool && (fabs(resetPolyPCov[i][j]) < eps); } solnDiffBool = solnDiffBool && (fabs(resetPolyPSolution[i]) < eps); } testFramework.assert(covMatDiffBool, "Covariance matrix found to be nonzero after Reset(int)", __LINE__); testFramework.assert(solnDiffBool , "Solution vector found to be nonzero after Reset(int)" , __LINE__); return testFramework.countFails(); }