GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/// Copyright CNRS 2019 |
||
2 |
/// author: O. Stasse |
||
3 |
#include <iostream> |
||
4 |
|||
5 |
#include "../../src/matrix/operator.cpp" |
||
6 |
|||
7 |
namespace dg = ::dynamicgraph; |
||
8 |
using namespace dynamicgraph::sot; |
||
9 |
|||
10 |
#define BOOST_TEST_MODULE test - operator |
||
11 |
|||
12 |
#include <boost/test/output_test_stream.hpp> |
||
13 |
#include <boost/test/unit_test.hpp> |
||
14 |
|||
15 |
using boost::test_tools::output_test_stream; |
||
16 |
|||
17 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(test_vector_selecter) { |
18 |
// Test VectorSelecter registered as aSelec_of_vector |
||
19 |
4 |
VectorSelecter aSelec_of_vector; |
|
20 |
|||
21 |
✓✗✓✗ |
4 |
output_test_stream output; |
22 |
|||
23 |
✓✗✓✗ |
2 |
output << aSelec_of_vector.nameTypeIn(); |
24 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Vector")); |
25 |
|||
26 |
✓✗✓✗ |
2 |
output << aSelec_of_vector.nameTypeOut(); |
27 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Vector")); |
28 |
|||
29 |
✓✗✓✗ |
2 |
output << aSelec_of_vector.getDocString(); |
30 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK( |
31 |
output.is_equal("Undocumented unary operator\n" |
||
32 |
" - input Vector\n" |
||
33 |
" - output Vector\n")); |
||
34 |
✓✗✓✗ |
4 |
dg::Vector vIn(10), vOut(10); |
35 |
✓✓✓✗ |
22 |
for (unsigned int i = 0; i < 10; i++) vIn(i) = i; |
36 |
|||
37 |
✓✗ | 2 |
aSelec_of_vector.setBounds(3, 5); |
38 |
✓✗ | 2 |
aSelec_of_vector.addBounds(7, 10); |
39 |
✓✗ | 2 |
aSelec_of_vector(vIn, vOut); |
40 |
✓✗ | 2 |
output << vOut; |
41 |
|||
42 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("3\n4\n7\n8\n9")); |
43 |
|||
44 |
✓✗ | 2 |
output << dg::sot::UnaryOp<VectorSelecter>::CLASS_NAME; |
45 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Selec_of_vector")); |
46 |
|||
47 |
✓✗✓✗ |
2 |
dg::Entity *anEntity = regFunction_Selec_of_vector("test_Selec_of_vector"); |
48 |
dg::sot::UnaryOp<VectorSelecter> *aVectorSelecter = |
||
49 |
✓✗ | 2 |
dynamic_cast<dg::sot::UnaryOp<VectorSelecter> *>(anEntity); |
50 |
✓✗✓✗ |
2 |
output << aVectorSelecter->getTypeInName(); |
51 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Vector")); |
52 |
|||
53 |
✓✗✓✗ |
2 |
output << aVectorSelecter->getTypeOutName(); |
54 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Vector")); |
55 |
|||
56 |
✓✗✓✗ |
2 |
output << aVectorSelecter->getClassName(); |
57 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Selec_of_vector")); |
58 |
|||
59 |
✓✗✓✗ |
2 |
output << aVectorSelecter->getDocString(); |
60 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK( |
61 |
output.is_equal("Undocumented unary operator\n" |
||
62 |
" - input Vector\n" |
||
63 |
" - output Vector\n")); |
||
64 |
2 |
} |
|
65 |
|||
66 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(test_vector_component) { |
67 |
// Test Vector Component |
||
68 |
VectorComponent aComponent_of_vector; |
||
69 |
|||
70 |
✓✗✓✗ |
4 |
output_test_stream output; |
71 |
|||
72 |
2 |
aComponent_of_vector.setIndex(1); |
|
73 |
✓✗ | 4 |
dg::Vector vIn(3); |
74 |
✓✓✓✗ |
8 |
for (unsigned int i = 0; i < 3; i++) vIn(i) = i; |
75 |
|||
76 |
double res; |
||
77 |
✓✗ | 2 |
aComponent_of_vector(vIn, res); |
78 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(res == 1.0); |
79 |
|||
80 |
✓✗✓✗ |
2 |
output << aComponent_of_vector.getDocString(); |
81 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK( |
82 |
output.is_equal("Select a component of a vector\n" |
||
83 |
" - input vector\n" |
||
84 |
" - output double")); |
||
85 |
|||
86 |
✓✗✓✗ |
2 |
output << aComponent_of_vector.nameTypeIn(); |
87 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Vector")); |
88 |
✓✗✓✗ |
2 |
output << aComponent_of_vector.nameTypeOut(); |
89 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("double")); |
90 |
|||
91 |
dg::Entity *anEntity = |
||
92 |
✓✗✓✗ |
2 |
regFunction_Component_of_vector("test_Component_of_vector"); |
93 |
dg::sot::UnaryOp<VectorComponent> *aVectorSelecter = |
||
94 |
✓✗ | 2 |
dynamic_cast<dg::sot::UnaryOp<VectorComponent> *>(anEntity); |
95 |
✓✗✓✗ |
2 |
output << aVectorSelecter->getTypeInName(); |
96 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Vector")); |
97 |
|||
98 |
✓✗✓✗ |
2 |
output << aVectorSelecter->getTypeOutName(); |
99 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("double")); |
100 |
|||
101 |
✓✗✓✗ |
2 |
output << aVectorSelecter->getClassName(); |
102 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Component_of_vector")); |
103 |
|||
104 |
✓✗✓✗ |
2 |
output << aVectorSelecter->getDocString(); |
105 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK( |
106 |
output.is_equal("Select a component of a vector\n" |
||
107 |
" - input vector\n" |
||
108 |
" - output double")); |
||
109 |
2 |
} |
|
110 |
|||
111 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(test_matrix_selector) { |
112 |
MatrixSelector aSelec_of_matrix; |
||
113 |
✓✗✓✗ |
4 |
output_test_stream output; |
114 |
|||
115 |
2 |
aSelec_of_matrix.setBoundsRow(2, 4); |
|
116 |
2 |
aSelec_of_matrix.setBoundsCol(2, 4); |
|
117 |
|||
118 |
✓✗ | 4 |
dg::Matrix aMatrix(5, 5); |
119 |
✓✓ | 12 |
for (unsigned int i = 0; i < 5; i++) |
120 |
✓✓✓✗ |
60 |
for (unsigned int j = 0; j < 5; j++) aMatrix(i, j) = i * 5 + j; |
121 |
|||
122 |
✓✗ | 4 |
dg::Matrix resMatrix(2, 2); |
123 |
✓✗ | 2 |
aSelec_of_matrix(aMatrix, resMatrix); |
124 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(resMatrix(0, 0) == 12.0); |
125 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(resMatrix(0, 1) == 13.0); |
126 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(resMatrix(1, 0) == 17.0); |
127 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(resMatrix(1, 1) == 18.0); |
128 |
|||
129 |
✓✗✓✗ |
2 |
output << aSelec_of_matrix.nameTypeIn(); |
130 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Matrix")); |
131 |
✓✗✓✗ |
2 |
output << aSelec_of_matrix.nameTypeOut(); |
132 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Matrix")); |
133 |
|||
134 |
✓✗✓✗ |
2 |
dg::Entity *anEntity = regFunction_Selec_of_matrix("test_Selec_of_matrix"); |
135 |
dg::sot::UnaryOp<MatrixSelector> *aMatrixSelector = |
||
136 |
✓✗ | 2 |
dynamic_cast<dg::sot::UnaryOp<MatrixSelector> *>(anEntity); |
137 |
✓✗✓✗ |
2 |
output << aMatrixSelector->getTypeInName(); |
138 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Matrix")); |
139 |
|||
140 |
✓✗✓✗ |
2 |
output << aMatrixSelector->getTypeOutName(); |
141 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Matrix")); |
142 |
|||
143 |
✓✗✓✗ |
2 |
output << aMatrixSelector->getClassName(); |
144 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Selec_of_matrix")); |
145 |
2 |
} |
|
146 |
|||
147 |
BOOST_AUTO_TEST_SUITE(test_rotation_conversions) |
||
148 |
|||
149 |
template <typename type> |
||
150 |
type random(); |
||
151 |
template <> |
||
152 |
VectorRollPitchYaw random<VectorRollPitchYaw>() { |
||
153 |
return VectorRollPitchYaw::Random(); |
||
154 |
} |
||
155 |
template <> |
||
156 |
45 |
VectorQuaternion random<VectorQuaternion>() { |
|
157 |
✓✗✓✗ |
90 |
return VectorQuaternion(Eigen::Vector4d::Random().normalized()); |
158 |
} |
||
159 |
template <> |
||
160 |
36 |
MatrixRotation random<MatrixRotation>() { |
|
161 |
✓✗ | 72 |
return MatrixRotation(random<VectorQuaternion>()); |
162 |
} |
||
163 |
template <> |
||
164 |
18 |
MatrixHomogeneous random<MatrixHomogeneous>() { |
|
165 |
18 |
MatrixHomogeneous matrix_homo; |
|
166 |
✓✗✓✗ |
18 |
matrix_homo.translation() = Eigen::Vector3d::Random(); |
167 |
✓✗✓✗ |
18 |
matrix_homo.linear() = random<MatrixRotation>(); |
168 |
18 |
return matrix_homo; |
|
169 |
} |
||
170 |
|||
171 |
template <typename type> |
||
172 |
72 |
bool compare(const type &a, const type &b) { |
|
173 |
✓✗ | 72 |
return a.isApprox(b); |
174 |
} |
||
175 |
template <> |
||
176 |
9 |
bool compare<VectorQuaternion>(const VectorQuaternion &a, |
|
177 |
const VectorQuaternion &b) { |
||
178 |
✓✗✓✓ ✓✗✓✗ ✓✗ |
9 |
return a.isApprox(b) || a.coeffs().isApprox(-b.coeffs()); |
179 |
} |
||
180 |
|||
181 |
template <typename AtoB, typename BtoA> |
||
182 |
10 |
void test_impl() { |
|
183 |
typedef typename AtoB::Tin A; |
||
184 |
typedef typename AtoB::Tout B; |
||
185 |
|||
186 |
AtoB a2b; |
||
187 |
BtoA b2a; |
||
188 |
|||
189 |
✓✓ | 100 |
for (std::size_t i = 1; i < 10; ++i) { |
190 |
✓✗✓✗ |
90 |
A ain = random<A>(), aout; |
191 |
✓✗ | 126 |
B b; |
192 |
|||
193 |
✓✗ | 90 |
a2b(ain, b); |
194 |
✓✗ | 90 |
b2a(b, aout); |
195 |
|||
196 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
90 |
BOOST_CHECK(compare(ain, aout)); |
197 |
} |
||
198 |
10 |
} |
|
199 |
|||
200 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(matrix_rpy) { test_impl<MatrixToRPY, RPYToMatrix>(); } |
201 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
2 |
BOOST_AUTO_TEST_CASE(quaternion_rpy) { |
202 |
2 |
test_impl<QuaternionToRPY, RPYToQuaternion>(); |
|
203 |
2 |
} |
|
204 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
2 |
BOOST_AUTO_TEST_CASE(matrix_quaternion) { |
205 |
2 |
test_impl<MatrixToQuaternion, QuaternionToMatrix>(); |
|
206 |
2 |
} |
|
207 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
2 |
BOOST_AUTO_TEST_CASE(matrixHomo_poseQuaternion) { |
208 |
2 |
test_impl<MatrixHomoToPoseQuaternion, PoseQuaternionToMatrixHomo>(); |
|
209 |
2 |
} |
|
210 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
2 |
BOOST_AUTO_TEST_CASE(matrixHomo_se3Vector) { |
211 |
2 |
test_impl<MatrixHomoToSE3Vector, SE3VectorToMatrixHomo>(); |
|
212 |
2 |
} |
|
213 |
|||
214 |
BOOST_AUTO_TEST_SUITE_END() |
Generated by: GCOVR (Version 4.2) |