13 #ifndef poly_math_test_suite_hpp
14 #define poly_math_test_suite_hpp
24 template<
typename data__>
97 for (
size_t i=0; i<5; ++i)
101 eval_ref=p1.
f(x[i]) + p2.f(x[i]);
102 TEST_ASSERT(eval_out==eval_ref);
123 for (
size_t i=0; i<5; ++i)
127 eval_ref=p1.
f(x[i]) - p2.f(x[i]);
128 TEST_ASSERT(eval_out==eval_ref);
149 for (
size_t i=0; i<5; ++i)
153 eval_ref=p1.
f(x[i]) * p2.f(x[i]);
154 TEST_ASSERT(eval_out==eval_ref);
165 coef1 << -3, 4, -2, 3;
178 if (coef_out.rows()==coef_q.rows())
180 TEST_ASSERT(coef_out==coef_q);
184 TEST_ASSERT_MSG(
false,
"Quotient not correct degree");
187 if (coef_out.rows()==coef_r.rows())
189 TEST_ASSERT(coef_out==coef_r);
193 TEST_ASSERT_MSG(
false,
"Remainder not correct degree");
215 if (coef_out.rows()==coef_q.rows())
217 TEST_ASSERT(coef_out==coef_q);
221 TEST_ASSERT_MSG(
false,
"Quotient not correct degree");
224 if (coef_out.rows()==coef_r.rows())
226 TEST_ASSERT(coef_out==coef_r);
230 TEST_ASSERT_MSG(
false,
"Remainder not correct degree");
239 coef1 <<-1, 0, 0, 0, 0,-5;
241 coef_q <<-1, 1,-1, 1,-1;
252 if (coef_out.rows()==coef_q.rows())
254 TEST_ASSERT(coef_out==coef_q);
258 TEST_ASSERT_MSG(
false,
"Quotient not correct degree");
261 if (coef_out.rows()==coef_r.rows())
263 TEST_ASSERT(coef_out==coef_r);
267 TEST_ASSERT_MSG(
false,
"Remainder not correct degree");
276 coef1 <<-15, 3,-5, 1;
289 if (coef_out.rows()==coef_q.rows())
291 TEST_ASSERT(coef_out==coef_q);
295 TEST_ASSERT_MSG(
false,
"Quotient not correct degree");
298 if (coef_out.rows()==coef_r.rows())
300 TEST_ASSERT(coef_out==coef_r);
304 TEST_ASSERT_MSG(
false,
"Remainder not correct degree");
313 coef1 <<-1, 0, 0, 0, 0,-5;
315 coef_q <<-1, 1,-1, 1,-1;
326 if (coef_out.rows()==coef_q.rows())
328 TEST_ASSERT(coef_out==coef_q);
332 TEST_ASSERT_MSG(
false,
"Quotient not correct degree");
335 if (coef_out.rows()==coef_r.rows())
337 TEST_ASSERT(coef_out==coef_r);
341 TEST_ASSERT_MSG(
false,
"Remainder not correct degree");
361 for (
size_t i=0; i<5; ++i)
364 eval_out=pr.
f(x[i])+prem.
f(x[i])/p2.f(x[i]);
365 eval_ref=p1.
f(x[i])/p2.f(x[i]);
366 TEST_ASSERT(eval_out==eval_ref);
378 TEST_ASSERT(p.
f(roots)==0);
383 data__ roots[2] = {2, -3};
386 TEST_ASSERT(p.
f(roots[0])==0);
387 TEST_ASSERT(p.
f(roots[1])==0);
392 data__ roots[3] = {2, -3, 5};
395 TEST_ASSERT(p.
f(roots[0])==0);
396 TEST_ASSERT(p.
f(roots[1])==0);
397 TEST_ASSERT(p.
f(roots[2])==0);
402 data__ roots[4] = {2, -3, 5, 7};
408 TEST_ASSERT(p.
f(roots[0])==0);
409 TEST_ASSERT(p.
f(roots[1])==0);
410 TEST_ASSERT(p.
f(roots[2])==0);
411 TEST_ASSERT(p.
f(roots[3])==0);
416 data__ roots[4] = {2, -3, 5, 7};
419 TEST_ASSERT(p.
f(roots[0])==0);
420 TEST_ASSERT(p.
f(roots[1])==0);
421 TEST_ASSERT(p.
f(roots[2])==0);
422 TEST_ASSERT(p.
f(roots[3])==0);
430 if (
typeid(data__)==
typeid(float))
432 else if (
typeid(data__)==
typeid(double))
434 else if (
typeid(data__)==
typeid(
long double))
436 else if (
typeid(data__)==
typeid(int))
441 std::vector<data__> roots(nr);
443 for (i=1; i<static_cast<int>(roots.size()); ++i)
444 roots[i]=3*i-roots[i-1];
447 for (i=0; i<static_cast<int>(roots.size()); ++i)
449 TEST_ASSERT(p.f(roots[i])==0);
459 coef_in << 3, 5, 1, 8;
471 TEST_ASSERT_MSG(
false,
"Null derivative function");
481 if (coef_out.rows()==coef_ref.rows())
483 TEST_ASSERT(coef_out==coef_ref);
487 TEST_ASSERT_MSG(
false,
"Degree not correct degree");
495 t=
static_cast<data__
>(0);
497 eval_ref=1*coef_in(1);
498 TEST_ASSERT(eval_out==eval_ref);
499 t=
static_cast<data__
>(1);
501 eval_ref=
static_cast<data__
>(31);
502 TEST_ASSERT(eval_out==eval_ref);
503 t=
static_cast<data__
>(11);
505 eval_ref=
static_cast<data__
>(2931);
506 TEST_ASSERT(eval_out==eval_ref);
513 TEST_ASSERT_MSG(
false,
"Null derivative function");
519 coef_ref << 1*5, 2*1, 3*8;
523 if (coef_out.rows()==coef_ref.rows())
525 TEST_ASSERT(coef_out==coef_ref);
529 TEST_ASSERT_MSG(
false,
"Degree not correct degree");
537 t=
static_cast<data__
>(0);
539 eval_ref=2*1*coef_in(2);
540 TEST_ASSERT(eval_out==eval_ref);
541 t=
static_cast<data__
>(1);
543 eval_ref=
static_cast<data__
>(50);
544 TEST_ASSERT(eval_out==eval_ref);
545 t=
static_cast<data__
>(11);
547 eval_ref=
static_cast<data__
>(530);
548 TEST_ASSERT(eval_out==eval_ref);
555 TEST_ASSERT_MSG(
false,
"Null derivative function");
561 coef_ref << (2*1)*1, (3*2)*8;
565 if (coef_out.rows()==coef_ref.rows())
567 TEST_ASSERT(coef_out==coef_ref);
571 TEST_ASSERT_MSG(
false,
"Degree not correct degree");
579 t=
static_cast<data__
>(0);
581 eval_ref=3*2*1*coef_in(3);
582 TEST_ASSERT(eval_out==eval_ref);
583 t=
static_cast<data__
>(1);
585 eval_ref=
static_cast<data__
>(48);
586 TEST_ASSERT(eval_out==eval_ref);
587 t=
static_cast<data__
>(11);
589 eval_ref=
static_cast<data__
>(48);
590 TEST_ASSERT(eval_out==eval_ref);
597 TEST_ASSERT_MSG(
false,
"Null derivative function");
603 coef_ref << (3*2*1)*8;
607 if (coef_out.rows()==coef_ref.rows())
609 TEST_ASSERT(coef_out==coef_ref);
613 TEST_ASSERT_MSG(
false,
"Degree not correct degree");
poly_math_test_suite()
Definition: poly_math_test_suite.hpp:69
void AddTests(const double &)
Definition: poly_math_test_suite.hpp:48
data_type fp(const data_type &t) const
Definition: polynomial.hpp:221
void divide_test()
Definition: poly_math_test_suite.hpp:158
void multiply(const polynomial< data_type > &p1, const polynomial< data_type > &p2)
Definition: polynomial.hpp:383
data_type f(const data_type &t) const
Definition: polynomial.hpp:199
void AddTests(const long double &)
Definition: poly_math_test_suite.hpp:58
void add_test()
Definition: poly_math_test_suite.hpp:80
~poly_math_test_suite()
Definition: poly_math_test_suite.hpp:74
void subtract_test()
Definition: poly_math_test_suite.hpp:106
Definition: polynomial.hpp:31
Eigen::Matrix< data_type, Eigen::Dynamic, 1 > coefficient_type
Definition: polynomial.hpp:35
void subtract(const polynomial< data_type > &p1, const polynomial< data_type > &p2)
Definition: polynomial.hpp:360
void creation_test()
Definition: poly_math_test_suite.hpp:371
void add(const polynomial< data_type > &p1, const polynomial< data_type > &p2)
Definition: polynomial.hpp:337
data_type fpp(const data_type &t) const
Definition: polynomial.hpp:244
void multiply_test()
Definition: poly_math_test_suite.hpp:132
void get_coefficients(coefficient_type &aout) const
Definition: polynomial.hpp:86
void divide(polynomial< data_type > &prem, const polynomial< data_type > &p1, const polynomial< data_type > &p2)
Definition: polynomial.hpp:410
data_type fppp(const data_type &t) const
Definition: polynomial.hpp:267
void AddTests(const float &)
Definition: poly_math_test_suite.hpp:38
void AddTests(const int &)
Definition: poly_math_test_suite.hpp:28
Definition: poly_math_test_suite.hpp:25
void derivative_test()
Definition: poly_math_test_suite.hpp:454
data__ data_type
Definition: polynomial.hpp:34