5 #include "../../src/matrix/operator.cpp" 7 namespace dg = ::dynamicgraph;
10 #define BOOST_TEST_MODULE test - operator 12 #include <boost/test/output_test_stream.hpp> 13 #include <boost/test/unit_test.hpp> 15 using boost::test_tools::output_test_stream;
21 output_test_stream output;
24 BOOST_CHECK(output.is_equal(
"Vector"));
27 BOOST_CHECK(output.is_equal(
"Vector"));
31 output.is_equal(
"Undocumented unary operator\n" 33 " - output Vector\n"));
35 for (
unsigned int i = 0;
i < 10;
i++) vIn(
i) =
i;
39 aSelec_of_vector(vIn, vOut);
42 BOOST_CHECK(output.is_equal(
"3\n4\n7\n8\n9"));
44 output << dg::sot::UnaryOp<VectorSelecter>::CLASS_NAME;
45 BOOST_CHECK(output.is_equal(
"Selec_of_vector"));
47 dg::Entity *anEntity = regFunction_Selec_of_vector(
"test_Selec_of_vector");
48 dg::sot::UnaryOp<VectorSelecter> *aVectorSelecter =
49 dynamic_cast<dg::sot::UnaryOp<VectorSelecter> *
>(anEntity);
50 output << aVectorSelecter->getTypeInName();
51 BOOST_CHECK(output.is_equal(
"Vector"));
53 output << aVectorSelecter->getTypeOutName();
54 BOOST_CHECK(output.is_equal(
"Vector"));
56 output << aVectorSelecter->getClassName();
57 BOOST_CHECK(output.is_equal(
"Selec_of_vector"));
59 output << aVectorSelecter->getDocString();
61 output.is_equal(
"Undocumented unary operator\n" 63 " - output Vector\n"));
70 output_test_stream output;
74 for (
unsigned int i = 0;
i < 3;
i++) vIn(
i) =
i;
77 aComponent_of_vector(vIn, res);
78 BOOST_CHECK(res == 1.0);
82 output.is_equal(
"Select a component of a vector\n" 87 BOOST_CHECK(output.is_equal(
"Vector"));
89 BOOST_CHECK(output.is_equal(
"double"));
92 regFunction_Component_of_vector(
"test_Component_of_vector");
93 dg::sot::UnaryOp<VectorComponent> *aVectorSelecter =
94 dynamic_cast<dg::sot::UnaryOp<VectorComponent> *
>(anEntity);
95 output << aVectorSelecter->getTypeInName();
96 BOOST_CHECK(output.is_equal(
"Vector"));
98 output << aVectorSelecter->getTypeOutName();
99 BOOST_CHECK(output.is_equal(
"double"));
101 output << aVectorSelecter->getClassName();
102 BOOST_CHECK(output.is_equal(
"Component_of_vector"));
104 output << aVectorSelecter->getDocString();
106 output.is_equal(
"Select a component of a vector\n" 108 " - output double"));
113 output_test_stream output;
119 for (
unsigned int i = 0;
i < 5;
i++)
120 for (
unsigned int j = 0; j < 5; j++) aMatrix(
i, j) =
i * 5 + j;
123 aSelec_of_matrix(aMatrix, resMatrix);
124 BOOST_CHECK(resMatrix(0, 0) == 12.0);
125 BOOST_CHECK(resMatrix(0, 1) == 13.0);
126 BOOST_CHECK(resMatrix(1, 0) == 17.0);
127 BOOST_CHECK(resMatrix(1, 1) == 18.0);
130 BOOST_CHECK(output.is_equal(
"Matrix"));
132 BOOST_CHECK(output.is_equal(
"Matrix"));
134 dg::Entity *anEntity = regFunction_Selec_of_matrix(
"test_Selec_of_matrix");
135 dg::sot::UnaryOp<MatrixSelector> *aMatrixSelector =
136 dynamic_cast<dg::sot::UnaryOp<MatrixSelector> *
>(anEntity);
137 output << aMatrixSelector->getTypeInName();
138 BOOST_CHECK(output.is_equal(
"Matrix"));
140 output << aMatrixSelector->getTypeOutName();
141 BOOST_CHECK(output.is_equal(
"Matrix"));
143 output << aMatrixSelector->getClassName();
144 BOOST_CHECK(output.is_equal(
"Selec_of_matrix"));
147 BOOST_AUTO_TEST_SUITE(test_rotation_conversions)
149 template <
typename type>
153 return VectorRollPitchYaw::Random();
166 matrix_homo.translation() = Eigen::Vector3d::Random();
171 template <
typename type>
173 return a.isApprox(b);
178 return a.isApprox(
b) ||
a.coeffs().isApprox(-
b.coeffs());
181 template <
typename AtoB,
typename BtoA>
183 typedef typename AtoB::Tin
A;
184 typedef typename AtoB::Tout
B;
189 for (std::size_t
i = 1;
i < 10; ++
i) {
190 A ain = random<A>(), aout;
196 BOOST_CHECK(
compare(ain, aout));
202 test_impl<QuaternionToRPY, RPYToQuaternion>();
205 test_impl<MatrixToQuaternion, QuaternionToMatrix>();
208 test_impl<MatrixHomoToPoseQuaternion, PoseQuaternionToMatrixHomo>();
211 test_impl<MatrixHomoToSE3Vector, SE3VectorToMatrixHomo>();
bool compare< VectorQuaternion >(const VectorQuaternion &a, const VectorQuaternion &b)
Eigen::Quaternion< double > SOT_CORE_EXPORT VectorQuaternion
void setIndex(const int &m)
void setBoundsCol(const int &m, const int &M)
Eigen::Transform< double, 3, Eigen::Affine > MatrixHomogeneous
Eigen::Matrix< double, 3, 3 > MatrixRotation
VectorRollPitchYaw random< VectorRollPitchYaw >()
void addBounds(const int &m, const int &M)
Eigen::Vector3d SOT_CORE_EXPORT VectorRollPitchYaw
std::tuple_element< i, std::tuple< Args... > >::type type
MatrixHomogeneous random< MatrixHomogeneous >()
VectorQuaternion random< VectorQuaternion >()
MatrixRotation random< MatrixRotation >()
void setBounds(const int &m, const int &M)
std::string getDocString() const
Eigen::Matrix< double, 3, 3 > SOT_CORE_EXPORT MatrixRotation
BOOST_AUTO_TEST_SUITE_END() MatrixHomogeneous randomM()
bool compare(const type &a, const type &b)
void setBoundsRow(const int &m, const int &M)
BOOST_AUTO_TEST_CASE(test_vector_selecter)