GCC Code Coverage Report


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