GCC Code Coverage Report


Directory: ./
File: unittest/test_costs.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 140 144 97.2%
Branches: 349 748 46.7%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, LAAS-CNRS, New York University,
5 // Max Planck Gesellschaft, University of Edinburgh,
6 // INRIA
7 // Copyright note valid unless otherwise stated in individual files.
8 // All rights reserved.
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #define BOOST_TEST_NO_MAIN
12 #define BOOST_TEST_ALTERNATIVE_INIT_API
13
14 #include "crocoddyl/multibody/data/multibody.hpp"
15 #include "factory/cost.hpp"
16 #include "unittest_common.hpp"
17
18 using namespace boost::unit_test;
19 using namespace crocoddyl::unittest;
20
21 //----------------------------------------------------------------------------//
22
23 315 void test_calc_returns_a_cost(CostModelTypes::Type cost_type,
24 StateModelTypes::Type state_type,
25 ActivationModelTypes::Type activation_type) {
26 // create the model
27
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 CostModelFactory factory;
28 const std::shared_ptr<crocoddyl::CostModelAbstract>& model =
29
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 factory.create(cost_type, state_type, activation_type);
30
31 // Run the print function
32
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 std::ostringstream tmp;
33
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 tmp << *model;
34
35 // create the corresponding data object
36 const std::shared_ptr<crocoddyl::StateMultibody>& state =
37
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 std::static_pointer_cast<crocoddyl::StateMultibody>(model->get_state());
38
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 pinocchio::Model& pinocchio_model = *state->get_pinocchio().get();
39
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 pinocchio::Data pinocchio_data(pinocchio_model);
40
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 crocoddyl::DataCollectorMultibody shared_data(&pinocchio_data);
41 const std::shared_ptr<crocoddyl::CostDataAbstract>& data =
42
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 model->createData(&shared_data);
43 315 data->cost = nan("");
44
45 // Generating random values for the state and control
46
2/4
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 315 times.
✗ Branch 7 not taken.
315 const Eigen::VectorXd x = model->get_state()->rand();
47
3/6
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
315 const Eigen::VectorXd u = Eigen::VectorXd::Random(model->get_nu());
48
49 // Compute all the pinocchio function needed for the models.
50
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
315 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data, x);
51
52 // Getting the cost value computed by calc()
53
3/6
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
315 model->calc(data, x, u);
54
55 // Checking that calc returns a cost value
56
6/12
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 315 times.
315 BOOST_CHECK(!std::isnan(data->cost));
57
58 // Checking that casted computation is the same
59 #ifdef NDEBUG // Run only in release mode
60 const std::shared_ptr<crocoddyl::CostModelAbstractTpl<float>>& casted_model =
61 model->cast<float>();
62 const std::shared_ptr<crocoddyl::StateMultibodyTpl<float>>& casted_state =
63 std::static_pointer_cast<crocoddyl::StateMultibodyTpl<float>>(
64 casted_model->get_state());
65 pinocchio::ModelTpl<float>& pinocchio_model_f =
66 *casted_state->get_pinocchio().get();
67 pinocchio::DataTpl<float> pinocchio_data_f(pinocchio_model_f);
68 crocoddyl::DataCollectorMultibodyTpl<float> casted_shared_data(
69 &pinocchio_data_f);
70 const std::shared_ptr<crocoddyl::CostDataAbstractTpl<float>>& casted_data =
71 casted_model->createData(&casted_shared_data);
72 casted_data->cost = float(nan(""));
73 const Eigen::VectorXf x_f = x.cast<float>();
74 const Eigen::VectorXf u_f = u.cast<float>();
75 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model_f, &pinocchio_data_f,
76 x_f);
77 casted_model->calc(casted_data, x_f, u_f);
78 BOOST_CHECK(!std::isnan(casted_data->cost));
79 float tol_f = std::sqrt(2.0f * std::numeric_limits<float>::epsilon());
80 BOOST_CHECK(std::abs(float(data->cost) - casted_data->cost) <= tol_f);
81 #endif
82 315 }
83
84 315 void test_calc_against_numdiff(CostModelTypes::Type cost_type,
85 StateModelTypes::Type state_type,
86 ActivationModelTypes::Type activation_type) {
87 // create the model
88
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 CostModelFactory factory;
89 const std::shared_ptr<crocoddyl::CostModelAbstract>& model =
90
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 factory.create(cost_type, state_type, activation_type);
91
92 // create the corresponding data object
93 const std::shared_ptr<crocoddyl::StateMultibody>& state =
94
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 std::static_pointer_cast<crocoddyl::StateMultibody>(model->get_state());
95
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 pinocchio::Model& pinocchio_model = *state->get_pinocchio().get();
96
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 pinocchio::Data pinocchio_data(pinocchio_model);
97
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 crocoddyl::DataCollectorMultibody shared_data(&pinocchio_data);
98 const std::shared_ptr<crocoddyl::CostDataAbstract>& data =
99
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 model->createData(&shared_data);
100
101 // Create the equivalent num diff model and data.
102
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 crocoddyl::CostModelNumDiff model_num_diff(model);
103 const std::shared_ptr<crocoddyl::CostDataAbstract>& data_num_diff =
104
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 model_num_diff.createData(&shared_data);
105
106 // Generating random values for the state and control
107
2/4
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 315 times.
✗ Branch 7 not taken.
315 const Eigen::VectorXd x = model->get_state()->rand();
108
3/6
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
315 const Eigen::VectorXd u = Eigen::VectorXd::Random(model->get_nu());
109
110 // Compute all the pinocchio function needed for the models.
111
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
315 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data, x);
112
113 // Computing the cost derivatives
114
3/6
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
315 model->calc(data, x, u);
115
116
3/6
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 315 times.
✗ Branch 8 not taken.
315 model_num_diff.calc(data_num_diff, x, u);
117
118 // Checking the partial derivatives against NumDiff
119
6/12
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 315 times.
315 BOOST_CHECK(data->cost == data_num_diff->cost);
120
121 // Checking that casted computation is the same
122 #ifdef NDEBUG // Run only in release mode
123 const std::shared_ptr<crocoddyl::CostModelAbstractTpl<float>>& casted_model =
124 model->cast<float>();
125 const std::shared_ptr<crocoddyl::StateMultibodyTpl<float>>& casted_state =
126 std::static_pointer_cast<crocoddyl::StateMultibodyTpl<float>>(
127 casted_model->get_state());
128 pinocchio::ModelTpl<float>& casted_pinocchio_model =
129 *casted_state->get_pinocchio().get();
130 pinocchio::DataTpl<float> casted_pinocchio_data(casted_pinocchio_model);
131 crocoddyl::DataCollectorMultibodyTpl<float> casted_shared_data(
132 &casted_pinocchio_data);
133 const std::shared_ptr<crocoddyl::CostDataAbstractTpl<float>>& casted_data =
134 casted_model->createData(&casted_shared_data);
135 const Eigen::VectorXf x_f = x.cast<float>();
136 const Eigen::VectorXf u_f = u.cast<float>();
137 crocoddyl::unittest::updateAllPinocchio(&casted_pinocchio_model,
138 &casted_pinocchio_data, x_f);
139 casted_model->calc(casted_data, x_f, u_f);
140 float tol_f = std::sqrt(2.0f * std::numeric_limits<float>::epsilon());
141 BOOST_CHECK(std::abs(float(data->cost) - casted_data->cost) <= tol_f);
142 #endif
143 315 }
144
145 315 void test_partial_derivatives_against_numdiff(
146 CostModelTypes::Type cost_type, StateModelTypes::Type state_type,
147 ActivationModelTypes::Type activation_type) {
148 using namespace boost::placeholders;
149
150 // create the model
151
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 CostModelFactory factory;
152 const std::shared_ptr<crocoddyl::CostModelAbstract>& model =
153
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 factory.create(cost_type, state_type, activation_type);
154
155 // create the corresponding data object
156 const std::shared_ptr<crocoddyl::StateMultibody>& state =
157
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 std::static_pointer_cast<crocoddyl::StateMultibody>(model->get_state());
158
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 pinocchio::Model& pinocchio_model = *state->get_pinocchio().get();
159
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 pinocchio::Data pinocchio_data(pinocchio_model);
160
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 crocoddyl::DataCollectorMultibody shared_data(&pinocchio_data);
161 const std::shared_ptr<crocoddyl::CostDataAbstract>& data =
162
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 model->createData(&shared_data);
163
164 // Create the equivalent num diff model and data.
165
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 crocoddyl::CostModelNumDiff model_num_diff(model);
166 const std::shared_ptr<crocoddyl::CostDataAbstract>& data_num_diff =
167
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 model_num_diff.createData(&shared_data);
168
169 // Generating random values for the state and control
170
2/4
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 315 times.
✗ Branch 7 not taken.
315 Eigen::VectorXd x = model->get_state()->rand();
171
3/6
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
315 const Eigen::VectorXd u = Eigen::VectorXd::Random(model->get_nu());
172
173 // Compute all the pinocchio function needed for the models.
174
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
315 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data, x);
175
176 // set the function that needs to be called at every step of the numdiff
177 315 std::vector<crocoddyl::CostModelNumDiff::ReevaluationFunction> reevals;
178
3/6
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 315 times.
✗ Branch 8 not taken.
315 reevals.push_back(
179 boost::bind(&crocoddyl::unittest::updateAllPinocchio<
180 double, 0, pinocchio::JointCollectionDefaultTpl>,
181 &pinocchio_model, &pinocchio_data, _1, _2));
182
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 model_num_diff.set_reevals(reevals);
183
184 // Computing the cost derivatives
185
3/6
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
315 model->calc(data, x, u);
186
3/6
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
315 model->calcDiff(data, x, u);
187
3/6
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 315 times.
✗ Branch 8 not taken.
315 model_num_diff.calc(data_num_diff, x, u);
188
3/6
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 315 times.
✗ Branch 8 not taken.
315 model_num_diff.calcDiff(data_num_diff, x, u);
189 // Tolerance defined as in
190 // http://www.it.uom.gr/teaching/linearalgebra/NumericalRecipiesInC/c5-7.pdf
191
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 double tol = std::pow(model_num_diff.get_disturbance(), 1. / 3.);
192
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 315 times.
✗ Branch 26 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 315 times.
315 BOOST_CHECK((data->Lx - data_num_diff->Lx).isZero(tol));
193
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 315 times.
✗ Branch 26 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 315 times.
315 BOOST_CHECK((data->Lu - data_num_diff->Lu).isZero(tol));
194
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 315 times.
✗ Branch 4 not taken.
315 if (model_num_diff.get_with_gauss_approx()) {
195 // The num diff is not precise enough to be tested here.
196
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 315 times.
✗ Branch 26 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 315 times.
315 BOOST_CHECK((data->Lxx - data_num_diff->Lxx).isZero(tol));
197
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 315 times.
✗ Branch 26 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 315 times.
315 BOOST_CHECK((data->Lxu - data_num_diff->Lxu).isZero(tol));
198
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 315 times.
✗ Branch 26 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 315 times.
315 BOOST_CHECK((data->Luu - data_num_diff->Luu).isZero(tol));
199 } else {
200 BOOST_CHECK((data_num_diff->Lxx).isZero(tol));
201 BOOST_CHECK((data_num_diff->Lxu).isZero(tol));
202 BOOST_CHECK((data_num_diff->Luu).isZero(tol));
203 }
204
205 // Computing the cost derivatives
206
2/4
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 315 times.
✗ Branch 7 not taken.
315 x = model->get_state()->rand();
207
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
315 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data, x);
208
2/4
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
315 model->calc(data, x);
209
2/4
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
315 model->calcDiff(data, x);
210
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
315 model_num_diff.calc(data_num_diff, x);
211
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
315 model_num_diff.calcDiff(data_num_diff, x);
212
213 // Checking the partial derivatives against numdiff
214
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 tol = std::pow(model_num_diff.get_disturbance(), 1. / 3.);
215
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 315 times.
✗ Branch 26 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 315 times.
315 BOOST_CHECK((data->Lx - data_num_diff->Lx).isZero(tol));
216
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 315 times.
✗ Branch 4 not taken.
315 if (model_num_diff.get_with_gauss_approx()) {
217 // The num diff is not precise enough to be tested here.
218
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 315 times.
✗ Branch 26 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 315 times.
315 BOOST_CHECK((data->Lxx - data_num_diff->Lxx).isZero(tol));
219 } else {
220 BOOST_CHECK((data_num_diff->Lxx).isZero(tol));
221 }
222
223 // Checking that casted computation is the same
224 #ifdef NDEBUG // Run only in release mode
225 const std::shared_ptr<crocoddyl::CostModelAbstractTpl<float>>& casted_model =
226 model->cast<float>();
227 const std::shared_ptr<crocoddyl::StateMultibodyTpl<float>>& casted_state =
228 std::static_pointer_cast<crocoddyl::StateMultibodyTpl<float>>(
229 casted_model->get_state());
230 pinocchio::ModelTpl<float>& casted_pinocchio_model =
231 *casted_state->get_pinocchio().get();
232 pinocchio::DataTpl<float> casted_pinocchio_data(casted_pinocchio_model);
233 crocoddyl::DataCollectorMultibodyTpl<float> casted_shared_data(
234 &casted_pinocchio_data);
235 const std::shared_ptr<crocoddyl::CostDataAbstractTpl<float>>& casted_data =
236 casted_model->createData(&casted_shared_data);
237 const Eigen::VectorXf x_f = x.cast<float>();
238 const Eigen::VectorXf u_f = u.cast<float>();
239 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data, x);
240 crocoddyl::unittest::updateAllPinocchio(&casted_pinocchio_model,
241 &casted_pinocchio_data, x_f);
242 model->calc(data, x, u);
243 model->calcDiff(data, x, u);
244 casted_model->calc(casted_data, x_f, u_f);
245 casted_model->calcDiff(casted_data, x_f, u_f);
246 float tol_f = 80.f * std::sqrt(2.0f * std::numeric_limits<float>::epsilon());
247 BOOST_CHECK(std::abs(float(data->cost) - casted_data->cost) <= tol_f);
248 BOOST_CHECK((data->Lx.cast<float>() - casted_data->Lx).isZero(tol_f));
249 BOOST_CHECK((data->Lu.cast<float>() - casted_data->Lu).isZero(tol_f));
250 BOOST_CHECK((data->Lxx.cast<float>() - casted_data->Lxx).isZero(tol_f));
251 BOOST_CHECK((data->Lxu.cast<float>() - casted_data->Lxu).isZero(tol_f));
252 BOOST_CHECK((data->Luu.cast<float>() - casted_data->Luu).isZero(tol_f));
253 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data, x);
254 crocoddyl::unittest::updateAllPinocchio(&casted_pinocchio_model,
255 &casted_pinocchio_data, x_f);
256 model->calc(data, x);
257 model->calcDiff(data, x);
258 casted_model->calc(casted_data, x_f);
259 casted_model->calcDiff(casted_data, x_f);
260 BOOST_CHECK(std::abs(float(data->cost) - casted_data->cost) <= tol_f);
261 BOOST_CHECK((data->Lx.cast<float>() - casted_data->Lx).isZero(tol_f));
262 BOOST_CHECK((data->Lxx.cast<float>() - casted_data->Lxx).isZero(tol_f));
263 #endif
264 315 }
265
266 315 void test_dimensions_in_cost_sum(CostModelTypes::Type cost_type,
267 StateModelTypes::Type state_type,
268 ActivationModelTypes::Type activation_type) {
269 // create the model
270
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 CostModelFactory factory;
271 const std::shared_ptr<crocoddyl::CostModelAbstract>& model =
272
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 factory.create(cost_type, state_type, activation_type);
273
274 // create the corresponding data object
275 const std::shared_ptr<crocoddyl::StateMultibody>& state =
276
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 std::static_pointer_cast<crocoddyl::StateMultibody>(model->get_state());
277
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 pinocchio::Model& pinocchio_model = *state->get_pinocchio().get();
278
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 pinocchio::Data pinocchio_data(pinocchio_model);
279
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 crocoddyl::DataCollectorMultibody shared_data(&pinocchio_data);
280
281 // create the cost sum model
282
2/4
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 315 times.
✗ Branch 7 not taken.
315 crocoddyl::CostModelSum cost_sum(state, model->get_nu());
283
2/4
✓ Branch 3 taken 315 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 315 times.
✗ Branch 7 not taken.
315 cost_sum.addCost("myCost", model, 1.);
284
285 // Generating random values for the state and control
286
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 const Eigen::VectorXd x = state->rand();
287
288 // Compute all the pinocchio function needed for the models.
289
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
315 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data, x);
290
291
10/20
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 315 times.
✗ Branch 16 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 26 taken 315 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 315 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 315 times.
✗ Branch 33 not taken.
✗ Branch 37 not taken.
✓ Branch 38 taken 315 times.
315 BOOST_CHECK(model->get_state()->get_nx() == cost_sum.get_state()->get_nx());
292
10/20
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 315 times.
✗ Branch 16 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 26 taken 315 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 315 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 315 times.
✗ Branch 33 not taken.
✗ Branch 37 not taken.
✓ Branch 38 taken 315 times.
315 BOOST_CHECK(model->get_state()->get_ndx() == cost_sum.get_state()->get_ndx());
293
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 315 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 315 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 315 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 315 times.
✗ Branch 25 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 315 times.
315 BOOST_CHECK(model->get_nu() == cost_sum.get_nu());
294
10/20
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 315 times.
✗ Branch 16 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 26 taken 315 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 315 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 315 times.
✗ Branch 33 not taken.
✗ Branch 37 not taken.
✓ Branch 38 taken 315 times.
315 BOOST_CHECK(model->get_state()->get_nq() == cost_sum.get_state()->get_nq());
295
10/20
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 315 times.
✗ Branch 16 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 26 taken 315 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 315 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 315 times.
✗ Branch 33 not taken.
✗ Branch 37 not taken.
✓ Branch 38 taken 315 times.
315 BOOST_CHECK(model->get_state()->get_nv() == cost_sum.get_state()->get_nv());
296
9/18
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 315 times.
✗ Branch 16 not taken.
✓ Branch 19 taken 315 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 315 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 315 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 315 times.
✗ Branch 29 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 315 times.
315 BOOST_CHECK(model->get_activation()->get_nr() == cost_sum.get_nr());
297
298 // Checking that casted computation is the same
299 #ifdef NDEBUG // Run only in release mode
300 crocoddyl::CostModelSumTpl<float> casted_cost_sum = cost_sum.cast<float>();
301 BOOST_CHECK(model->get_state()->get_nx() ==
302 casted_cost_sum.get_state()->get_nx());
303 BOOST_CHECK(model->get_state()->get_ndx() ==
304 casted_cost_sum.get_state()->get_ndx());
305 BOOST_CHECK(model->get_nu() == casted_cost_sum.get_nu());
306 BOOST_CHECK(model->get_state()->get_nq() ==
307 casted_cost_sum.get_state()->get_nq());
308 BOOST_CHECK(model->get_state()->get_nv() ==
309 casted_cost_sum.get_state()->get_nv());
310 BOOST_CHECK(model->get_activation()->get_nr() == casted_cost_sum.get_nr());
311 #endif
312 315 }
313
314 315 void test_partial_derivatives_in_cost_sum(
315 CostModelTypes::Type cost_type, StateModelTypes::Type state_type,
316 ActivationModelTypes::Type activation_type) {
317 // create the model
318
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 CostModelFactory factory;
319 const std::shared_ptr<crocoddyl::CostModelAbstract>& model =
320
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 factory.create(cost_type, state_type, activation_type);
321
322 // create the corresponding data object
323 const std::shared_ptr<crocoddyl::StateMultibody>& state =
324
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 std::static_pointer_cast<crocoddyl::StateMultibody>(model->get_state());
325
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 pinocchio::Model& pinocchio_model = *state->get_pinocchio().get();
326
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 pinocchio::Data pinocchio_data(pinocchio_model);
327
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 crocoddyl::DataCollectorMultibody shared_data(&pinocchio_data);
328 const std::shared_ptr<crocoddyl::CostDataAbstract>& data =
329
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 model->createData(&shared_data);
330
331 // create the cost sum model
332
2/4
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 315 times.
✗ Branch 7 not taken.
315 crocoddyl::CostModelSum cost_sum(state, model->get_nu());
333
2/4
✓ Branch 3 taken 315 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 315 times.
✗ Branch 7 not taken.
315 cost_sum.addCost("myCost", model, 1.);
334 const std::shared_ptr<crocoddyl::CostDataSum>& data_sum =
335
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 cost_sum.createData(&shared_data);
336
337 // Generating random values for the state and control
338
1/2
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
315 const Eigen::VectorXd x = state->rand();
339
3/6
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
315 const Eigen::VectorXd u = Eigen::VectorXd::Random(model->get_nu());
340
341 // Compute all the pinocchio function needed for the models.
342
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
315 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data, x);
343
344 // Computing the cost derivatives
345
3/6
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
315 model->calc(data, x, u);
346
3/6
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
315 model->calcDiff(data, x, u);
347
3/6
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 315 times.
✗ Branch 8 not taken.
315 cost_sum.calc(data_sum, x, u);
348
3/6
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 315 times.
✗ Branch 8 not taken.
315 cost_sum.calcDiff(data_sum, x, u);
349
350
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 315 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 315 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 315 times.
✗ Branch 27 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 315 times.
315 BOOST_CHECK((data->Lx - data_sum->Lx).isZero());
351
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 315 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 315 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 315 times.
✗ Branch 27 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 315 times.
315 BOOST_CHECK((data->Lu - data_sum->Lu).isZero());
352
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 315 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 315 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 315 times.
✗ Branch 27 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 315 times.
315 BOOST_CHECK((data->Lxx - data_sum->Lxx).isZero());
353
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 315 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 315 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 315 times.
✗ Branch 27 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 315 times.
315 BOOST_CHECK((data->Lxu - data_sum->Lxu).isZero());
354
8/16
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 315 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 315 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 315 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 315 times.
✗ Branch 27 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 315 times.
315 BOOST_CHECK((data->Luu - data_sum->Luu).isZero());
355
356 // Checking that casted computation is the same
357 #ifdef NDEBUG // Run only in release mode
358 const std::shared_ptr<crocoddyl::CostModelAbstractTpl<float>>& casted_model =
359 model->cast<float>();
360 const std::shared_ptr<crocoddyl::StateMultibodyTpl<float>>& casted_state =
361 std::static_pointer_cast<crocoddyl::StateMultibodyTpl<float>>(
362 casted_model->get_state());
363 pinocchio::ModelTpl<float>& casted_pinocchio_model =
364 *casted_state->get_pinocchio().get();
365 pinocchio::DataTpl<float> casted_pinocchio_data(casted_pinocchio_model);
366 crocoddyl::DataCollectorMultibodyTpl<float> casted_shared_data(
367 &casted_pinocchio_data);
368 const std::shared_ptr<crocoddyl::CostDataAbstractTpl<float>>& casted_data =
369 casted_model->createData(&casted_shared_data);
370 crocoddyl::CostModelSumTpl<float> casted_cost_sum = cost_sum.cast<float>();
371 const std::shared_ptr<crocoddyl::CostDataSumTpl<float>>& casted_data_sum =
372 casted_cost_sum.createData(&casted_shared_data);
373 const Eigen::VectorXf x_f = x.cast<float>();
374 const Eigen::VectorXf u_f = u.cast<float>();
375 casted_model->calc(casted_data, x_f, u_f);
376 casted_model->calcDiff(casted_data, x_f, u_f);
377 casted_cost_sum.calc(casted_data_sum, x_f, u_f);
378 casted_cost_sum.calcDiff(casted_data_sum, x_f, u_f);
379 BOOST_CHECK((casted_data->Lx - casted_data_sum->Lx).isZero());
380 BOOST_CHECK((casted_data->Lu - casted_data_sum->Lu).isZero());
381 BOOST_CHECK((casted_data->Lxx - casted_data_sum->Lxx).isZero());
382 BOOST_CHECK((casted_data->Lxu - casted_data_sum->Lxu).isZero());
383 BOOST_CHECK((casted_data->Luu - casted_data_sum->Luu).isZero());
384 #endif
385 315 }
386
387 //----------------------------------------------------------------------------//
388
389 315 void register_cost_model_unit_tests(
390 CostModelTypes::Type cost_type, StateModelTypes::Type state_type,
391 ActivationModelTypes::Type activation_type) {
392
2/4
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
315 boost::test_tools::output_test_stream test_name;
393
5/10
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 315 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 315 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 315 times.
✗ Branch 14 not taken.
315 test_name << "test_" << cost_type << "_" << activation_type << "_"
394
1/2
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
315 << state_type;
395
4/8
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 315 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 315 times.
✗ Branch 11 not taken.
315 std::cout << "Running " << test_name.str() << std::endl;
396
4/8
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
315 test_suite* ts = BOOST_TEST_SUITE(test_name.str());
397
5/10
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 315 times.
✗ Branch 15 not taken.
315 ts->add(BOOST_TEST_CASE(boost::bind(&test_calc_returns_a_cost, cost_type,
398 state_type, activation_type)));
399
5/10
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 315 times.
✗ Branch 15 not taken.
315 ts->add(BOOST_TEST_CASE(boost::bind(&test_calc_against_numdiff, cost_type,
400 state_type, activation_type)));
401
5/10
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 315 times.
✗ Branch 15 not taken.
315 ts->add(BOOST_TEST_CASE(boost::bind(&test_partial_derivatives_against_numdiff,
402 cost_type, state_type, activation_type)));
403
5/10
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 315 times.
✗ Branch 15 not taken.
315 ts->add(BOOST_TEST_CASE(boost::bind(&test_dimensions_in_cost_sum, cost_type,
404 state_type, activation_type)));
405
5/10
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 315 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 315 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 315 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 315 times.
✗ Branch 15 not taken.
315 ts->add(BOOST_TEST_CASE(boost::bind(&test_partial_derivatives_in_cost_sum,
406 cost_type, state_type, activation_type)));
407
3/6
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 315 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 315 times.
✗ Branch 7 not taken.
315 framework::master_test_suite().add(ts);
408 315 }
409
410 1 bool init_function() {
411 // Test all costs available with all the activation types with all available
412 // states types.
413
2/2
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1 times.
8 for (size_t cost_type = 0; cost_type < CostModelTypes::all.size();
414 ++cost_type) {
415 35 for (size_t state_type =
416 7 StateModelTypes::all[StateModelTypes::StateMultibody_TalosArm];
417
2/2
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 7 times.
42 state_type < StateModelTypes::all.size(); ++state_type) {
418 350 for (size_t activation_type = 0;
419
2/2
✓ Branch 1 taken 315 times.
✓ Branch 2 taken 35 times.
350 activation_type < ActivationModelTypes::all.size();
420 ++activation_type) {
421 315 register_cost_model_unit_tests(
422 315 CostModelTypes::all[cost_type], StateModelTypes::all[state_type],
423 315 ActivationModelTypes::all[activation_type]);
424 }
425 }
426 }
427 1 return true;
428 }
429
430 1 int main(int argc, char** argv) {
431 1 return ::boost::unit_test::unit_test_main(&init_function, argc, argv);
432 }
433