55 gnsstk::TestUtil testFramework(
"PolyFit",
"Constructor", __FILE__, __LINE__ );
64 testFramework.
assert(
true,
"Default constructor successfully built a PolyFit object", __LINE__);
66 catch(...){testFramework.
assert(
false,
"Unexpected exception thrown during default construction of a PolyFit object", __LINE__); }
68 testFramework.
assert((
unsigned) 0 == Poly.
N() ,
"Default constructor created an object with data in it" , __LINE__);
69 testFramework.
assert((
unsigned) 0 == Poly.
Degree(),
"Default constructor allows for non-constant fits" , __LINE__);
70 testFramework.
assert(Poly.
isSingular() ,
"The fit found after default construction was not singular", __LINE__);
78 testFramework.
assert(
true,
"Explicit constructor successfully built a PolyFit object", __LINE__);
80 catch(...){testFramework.
assert(
false,
"Unexpected exception thrown during explicit construction of a PolyFit object", __LINE__); }
82 testFramework.
assert((
unsigned) 0 == Poly4.
N() ,
"Explicit constructor created an object with data in it" , __LINE__);
83 testFramework.
assert((
unsigned) 4 == Poly4.
Degree(),
"Explicit constructor does not fit polynomials of the correct order", __LINE__);
84 testFramework.
assert(Poly4.
isSingular() ,
"The fit found after explicit construction was not singular" , __LINE__);
100 std::string failMesg;
104 double indepSingle[6] = {0, 1, 2, 3, 4, 5}, depSingle[6] = {0, 1, 8, 27, 64, 125};
106 std::vector<double> indepStdVector(6,0.) , depStdVector(6,0.);
108 for(
int i=0; i<6; i++)
110 indepGnsstkVector[i] = indepSingle[i];
111 indepStdVector[i] = indepSingle[i];
112 depGnsstkVector[i] = depSingle[i];
113 depStdVector[i] = depSingle[i];
122 for(
int i=0; i<6; i++)
124 testSingle.Add(depSingle[i],indepSingle[i]);
127 testFramework.
assert(testSingle.N() == 6,
"Not all single adds were successful", __LINE__);
130 catch(...){testFramework.
assert(
false,
"Exception thrown during Single add", __LINE__);}
138 testGnsstkVector.Add(indepGnsstkVector, depGnsstkVector);
139 testFramework.
assert(testGnsstkVector.N() == 6,
"Not all gnsstk::Vector adds were successful", __LINE__);
141 catch(...){testFramework.
assert(
false,
"Exception thrown during gnsstk::Vector add", __LINE__);}
150 testStdVector.
Add(indepStdVector, depStdVector);
151 testFramework.
assert(testStdVector.
N() == 6,
"Not all std::vector adds were successful", __LINE__);
153 catch(...){testFramework.
assert(
false,
"Exception thrown during std::vector add", __LINE__);}
171 bool covMatDiffBool =
true;
172 bool solnDiffBool =
true;
181 double data[4] = {0.,2.,4.,-1.};
182 double time[4] = {3.,3.,4.,2.,};
184 for (
int i =0;i<4;i++)
201 testFramework.
assert((
unsigned) 0 == resetPolyD.
N() ,
"Reset did not set the datapoint counter to zero" , __LINE__);
202 testFramework.
assert((
unsigned) 2 == resetPolyD.
Degree(),
"Reset did not maintain the maximum fit degree as 2", __LINE__);
203 testFramework.
assert(resetPolyD.
isSingular() ,
"The fit found after Reset was not singular" , __LINE__);
204 for (
int i = 0; i<2; i++)
206 for (
int j = 0; j<2; j++)
208 covMatDiffBool = covMatDiffBool && (Blank[i][j] == resetPolyDCov[i][j]);
210 solnDiffBool = solnDiffBool && (fabs(resetPolyDSolution[i]) <
eps);
212 testFramework.
assert(covMatDiffBool,
"Covariance matrix found to be nonzero after Reset", __LINE__);
213 testFramework.
assert(solnDiffBool ,
"Solution vector found to be nonzero after Reset" , __LINE__);
219 resetPolyP.
Reset((
unsigned) 3);
221 covMatDiffBool =
true;
230 testFramework.
assert((
unsigned) 0 == resetPolyP.
N() ,
"Reset(int) did not set the datapoint counter to zero" , __LINE__);
231 testFramework.
assert((
unsigned) 3 == resetPolyP.
Degree(),
"Reset(int) did not change the maximum fit degree to 3", __LINE__);
232 testFramework.
assert(resetPolyP.
isSingular() ,
"The fit found after Reset(int) was not singular" , __LINE__);
233 for (
int i = 0; i<3; i++)
235 for (
int j = 0; j<3; j++)
237 covMatDiffBool = covMatDiffBool && (fabs(resetPolyPCov[i][j]) <
eps);
239 solnDiffBool = solnDiffBool && (fabs(resetPolyPSolution[i]) <
eps);
241 testFramework.
assert(covMatDiffBool,
"Covariance matrix found to be nonzero after Reset(int)", __LINE__);
242 testFramework.
assert(solnDiffBool ,
"Solution vector found to be nonzero after Reset(int)" , __LINE__);
255 gnsstk::TestUtil testFramework(
"PolyFit",
"Solution", __FILE__, __LINE__ );
256 std::string failMesg;
259 int errorCounter = 0;
263 double indep[6] = {0, 1, 2, 3, 4, 5}, dep[6] = {0, 1, 8, 27, 64, 125};
265 for(
int i=0; i<6; i++)
267 test.
Add(dep[i],indep[i]);
272 for (
int i = 0; i<4; i++)
277 if ((i != 3 && std::abs(soln[i]) >
eps) || (i == 3 && std::abs(soln[i] - 1) >
eps))
283 failMesg =
"Was the solution computed correct?";
284 testFramework.
assert(errorCounter == 0, failMesg, __LINE__);
297 gnsstk::TestUtil testFramework(
"PolyFit",
"Solution", __FILE__, __LINE__ );
298 std::string failMesg;
301 int errorCounter = 0;
304 double indep[6] = {0, 1, 2, 3, 4, 5}, dep[6] = {0, 1, 4, 9, 16, 25};
306 for(
int i=0; i<6; i++)
308 test.
Add(dep[i],indep[i]);
314 for (
int i = 0; i<4; i++)
318 if ((i != 2 && std::abs(soln[i]) >
eps) || (i == 2 && std::abs(soln[i] - 1) >
eps))
325 failMesg =
"Was the solution computed correct?";
326 testFramework.
assert(errorCounter==0, failMesg, __LINE__);
338 gnsstk::TestUtil testFramework(
"PolyFit",
"Solution", __FILE__, __LINE__ );
339 std::string failMesg;
342 int errorCounter = 0;
345 double indep[6] = {0, 1, 2, 3, 4, 5}, dep[6] = {0, 1, 2, 3, 4, 5};
347 for(
int i=0; i<6; i++)
349 test.
Add(dep[i],indep[i]);
355 for (
int i = 0; i<4; i++)
359 if ((i != 1 && std::abs(soln[i]) >
eps) || (i == 1 && std::abs(soln[i] - 1) >
eps))
366 failMesg =
"Was the solution computed correct?";
367 testFramework.
assert(errorCounter==0, failMesg, __LINE__);
379 gnsstk::TestUtil testFramework(
"PolyFit",
"Solution", __FILE__, __LINE__ );
380 std::string failMesg;
383 int errorCounter = 0;
386 double indep[6] = {0, 1, 2, 3, 4, 5}, dep[6] = {7, 7, 7, 7, 7, 7};
388 for(
int i=0; i<6; i++)
390 test.
Add(dep[i],indep[i]);
396 for (
int i = 0; i<4; i++)
400 if ((i != 0 && std::abs(soln[i]) >
eps) || (i == 0 && std::abs(soln[i] - 7) >
eps))
407 failMesg =
"Was the solution computed correct?";
408 testFramework.
assert(errorCounter==0, failMesg, __LINE__);
419 gnsstk::TestUtil testFramework(
"PolyFit",
"Solution", __FILE__, __LINE__ );
420 std::string failMesg;
423 int errorCounter = 0;
426 double indep[6] = {0, 1, 2, 3, 4, 5}, dep[6] = {2, 8, 30, 80, 170, 312};
428 for(
int i=0; i<6; i++)
430 test.
Add(dep[i],indep[i]);
436 for (
int i = 0; i<4; i++)
440 if (fabs(soln[i] - 2) >
eps)
447 failMesg =
"Was the solution computed correct?";
448 testFramework.
assert(errorCounter==0, failMesg, __LINE__);
460 gnsstk::TestUtil testFramework(
"PolyFit",
"Solution", __FILE__, __LINE__ );
461 std::string failMesg;
467 double indep[6] = {1, 1, 1, 1, 1, 1}, dep[6] = {1, 2, 3, 4, 5, 6};
469 for(
int i=0; i<6; i++)
471 test.
Add(dep[i],indep[i]);
478 failMesg =
"Was the solution computed singular?";
490 gnsstk::TestUtil testFramework(
"PolyFit",
"Evaluate", __FILE__, __LINE__ );
491 std::string failMesg;
496 double indep[6] = {0, 1, 2, 3, 4, 5}, dep[6] = {0, 1, 4, 9, 16, 25};
502 for(
int i=0; i<6; i++)
504 test.
Add(dep[i],indep[i]);
511 for (
int i = 0; i<3; i++)
515 if (fabs(soln[i] - eval[i]*eval[i])/(eval[i]*eval[i]) >
eps)
520 failMesg =
"Was the solution computed correct?";
521 testFramework.
assert(n==0, failMesg, __LINE__);
532 gnsstk::TestUtil testFramework(
"PolyFit",
"Evaluate", __FILE__, __LINE__ );
533 std::string failMesg;
538 double indep[6] = {0, 1, 2, 3, 4, 5}, dep[6] = {0, 1, 4, 9, 16, 25};
542 for(
int i=0; i<6; i++)
544 test.
Add(dep[i],indep[i]);
550 failMesg =
"Was the solution computed correct?";
551 testFramework.
assert(fabs(soln - eval*eval) <
eps, failMesg, __LINE__);
561 int check, errorCounter = 0;
565 errorCounter += check;
568 errorCounter += check;
571 errorCounter += check;
574 errorCounter += check;
577 errorCounter += check;
580 errorCounter += check;
583 errorCounter += check;
586 errorCounter += check;
589 errorCounter += check;
592 errorCounter += check;
595 errorCounter += check;
597 std::cout <<
"Total Errors: " << errorCounter << std::endl;
599 std::cout <<
"Total Failures for " << __FILE__ <<
": " << errorCounter << std::endl;