Code-Eli  0.3.6
poly_basic_test_suite.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef poly_basic_test_suite_hpp
14 #define poly_basic_test_suite_hpp
15 
16 #include <typeinfo> // typeid
17 #include <string> // std::string
18 #include <sstream> // std::stringstream
19 #include <iomanip> // std::setw
20 #include <limits> // std::numeric_limits
21 
23 
24 template<typename data__>
25 class poly_basic_test_suite : public Test::Suite
26 {
27  protected:
28  void AddTests(const int &)
29  {
32  }
33 
34  void AddTests(const float &)
35  {
38  }
39 
40  void AddTests(const double &)
41  {
44  }
45 
46  void AddTests(const long double &)
47  {
50  }
51 
52  public:
54  {
55  // add the tests
56  AddTests(data__());
57  }
59  {
60  }
61 
62  private:
63 
65  {
67  typename eli::mutil::poly::polynomial<data__>::coefficient_type coef_in(6), coef_out;
68 
69  // test default constructor then set coefficients
70  coef_in << 2, 0, 1, 4, 1, 8;
71  p1.set_coefficients(coef_in);
72  p1.get_coefficients(coef_out);
73  TEST_ASSERT(coef_in==coef_out);
74  coef_out.setZero();
75 
76  // test constructor with vector of coefficients
78  pc1.get_coefficients(coef_out);
79  TEST_ASSERT(coef_in==coef_out);
80  coef_out.setZero();
81 
82  // test copy ctr
84  p1c.get_coefficients(coef_out);
85  TEST_ASSERT(coef_in==coef_out);
86  coef_out.setZero();
87 
88  // test assignment operator
89  p2=p1;
90  p2.get_coefficients(coef_out);
91  TEST_ASSERT(coef_in==coef_out);
92  coef_out.setZero();
93 
94  // test order
95  TEST_ASSERT(p2.degree()==coef_in.rows()-1);
96 
97  // test data assignment operator
98  data__ zero(0);
99  p2=zero;
100  p2.get_coefficients(coef_out);
101  TEST_ASSERT(p2.degree()==0);
102  TEST_ASSERT(coef_out(0)==zero);
103  }
104 
106  {
108 
109  // set coefficients
110  coef_in << 2, 4, 3, 1, 2;
111 
112  eli::mutil::poly::polynomial<data__> p1(coef_in), p2;
113  typename eli::mutil::poly::polynomial<data__>::data_type eval_out, eval_ref;
115 
116  // test evaluation at points
117  t=static_cast<data__>(0);
118  eval_out=p1.f(t);
119  eval_ref=coef_in(0);
120  TEST_ASSERT(eval_out==eval_ref);
121  t=1;
122  eval_out=p1.f(t);
123  eval_ref = coef_in.sum();
124  TEST_ASSERT(eval_out==eval_ref);
125  t=10;
126  eval_out=p1.f(t);
127  eval_ref = 21342;
128 
129  TEST_ASSERT(eval_out==eval_ref);
130  }
131 };
132 
133 #endif
void AddTests(const float &)
Definition: poly_basic_test_suite.hpp:34
void set_coefficients(const coefficient_type &ain)
Definition: polynomial.hpp:81
void AddTests(const long double &)
Definition: poly_basic_test_suite.hpp:46
~poly_basic_test_suite()
Definition: poly_basic_test_suite.hpp:58
data_type f(const data_type &t) const
Definition: polynomial.hpp:199
void AddTests(const int &)
Definition: poly_basic_test_suite.hpp:28
Definition: polynomial.hpp:31
Eigen::Matrix< data_type, Eigen::Dynamic, 1 > coefficient_type
Definition: polynomial.hpp:35
index_type degree() const
Definition: polynomial.hpp:72
Definition: poly_basic_test_suite.hpp:25
poly_basic_test_suite()
Definition: poly_basic_test_suite.hpp:53
void evaluation_test()
Definition: poly_basic_test_suite.hpp:105
void get_coefficients(coefficient_type &aout) const
Definition: polynomial.hpp:86
void assignment_test()
Definition: poly_basic_test_suite.hpp:64
data__ data_type
Definition: polynomial.hpp:34
void AddTests(const double &)
Definition: poly_basic_test_suite.hpp:40