GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/////////////////////////////////////////////////////////////////////////////// |
||
2 |
// BSD 3-Clause License |
||
3 |
// |
||
4 |
// Copyright (C) 2021-2023, University of Edinburgh, Heriot-Watt University |
||
5 |
// Copyright note valid unless otherwise stated in individual files. |
||
6 |
// All rights reserved. |
||
7 |
/////////////////////////////////////////////////////////////////////////////// |
||
8 |
|||
9 |
#define BOOST_TEST_NO_MAIN |
||
10 |
#define BOOST_TEST_ALTERNATIVE_INIT_API |
||
11 |
|||
12 |
#include "factory/impulse_constraint.hpp" |
||
13 |
#include "unittest_common.hpp" |
||
14 |
|||
15 |
using namespace boost::unit_test; |
||
16 |
using namespace crocoddyl::unittest; |
||
17 |
|||
18 |
//----------------------------------------------------------------------------// |
||
19 |
|||
20 |
12 |
void test_partial_derivatives_against_impulse_numdiff( |
|
21 |
ImpulseConstraintModelTypes::Type constraint_type, |
||
22 |
PinocchioModelTypes::Type model_type) { |
||
23 |
// create the model |
||
24 |
const boost::shared_ptr<crocoddyl::ActionModelAbstract> &model = |
||
25 |
✓✗✓✗ |
24 |
ImpulseConstraintModelFactory().create(constraint_type, model_type); |
26 |
|||
27 |
// create the corresponding data object and set the constraint to nan |
||
28 |
const boost::shared_ptr<crocoddyl::ActionDataAbstract> &data = |
||
29 |
✓✗ | 24 |
model->createData(); |
30 |
|||
31 |
✓✗ | 24 |
crocoddyl::ActionModelNumDiff model_num_diff(model); |
32 |
const boost::shared_ptr<crocoddyl::ActionDataAbstract> &data_num_diff = |
||
33 |
✓✗ | 24 |
model_num_diff.createData(); |
34 |
|||
35 |
// Generating random values for the state and control |
||
36 |
✓✗ | 24 |
const Eigen::VectorXd x = model->get_state()->rand(); |
37 |
✓✗✓✗ |
24 |
const Eigen::VectorXd u = Eigen::VectorXd::Random(model->get_nu()); |
38 |
|||
39 |
// Computing the action derivatives |
||
40 |
✓✗✓✗ ✓✗ |
12 |
model->calc(data, x, u); |
41 |
✓✗✓✗ ✓✗ |
12 |
model->calcDiff(data, x, u); |
42 |
✓✗✓✗ ✓✗ |
12 |
model_num_diff.calc(data_num_diff, x, u); |
43 |
✓✗✓✗ ✓✗ |
12 |
model_num_diff.calcDiff(data_num_diff, x, u); |
44 |
// Tolerance defined as in |
||
45 |
// http://www.it.uom.gr/teaching/linearalgebra/NumericalRecipiesInC/c5-7.pdf |
||
46 |
12 |
double tol = std::pow(model_num_diff.get_disturbance(), 1. / 3.); |
|
47 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
12 |
BOOST_CHECK((data->Gx - data_num_diff->Gx).isZero(tol)); |
48 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
12 |
BOOST_CHECK((data->Hx - data_num_diff->Hx).isZero(tol)); |
49 |
12 |
} |
|
50 |
|||
51 |
//----------------------------------------------------------------------------// |
||
52 |
|||
53 |
12 |
void register_impulse_constraint_model_unit_tests( |
|
54 |
ImpulseConstraintModelTypes::Type constraint_type, |
||
55 |
PinocchioModelTypes::Type model_type) { |
||
56 |
✓✗✓✗ |
24 |
boost::test_tools::output_test_stream test_name; |
57 |
✓✗✓✗ ✓✗✓✗ |
12 |
test_name << "test_" << constraint_type << "_" << model_type; |
58 |
✓✗✓✗ ✓✗✓✗ |
12 |
std::cout << "Running " << test_name.str() << std::endl; |
59 |
✓✗✓✗ ✓✗✓✗ |
12 |
test_suite *ts = BOOST_TEST_SUITE(test_name.str()); |
60 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
12 |
ts->add(BOOST_TEST_CASE( |
61 |
boost::bind(&test_partial_derivatives_against_impulse_numdiff, |
||
62 |
constraint_type, model_type))); |
||
63 |
✓✗✓✗ ✓✗ |
12 |
framework::master_test_suite().add(ts); |
64 |
12 |
} |
|
65 |
|||
66 |
1 |
bool init_function() { |
|
67 |
// Test all the impulse constraint model. Note that we can do it only with |
||
68 |
// humanoids as it needs to test the impulse wrench cone |
||
69 |
6 |
for (size_t constraint_type = 0; |
|
70 |
✓✓ | 6 |
constraint_type < ImpulseConstraintModelTypes::all.size(); |
71 |
++constraint_type) { |
||
72 |
5 |
register_impulse_constraint_model_unit_tests( |
|
73 |
5 |
ImpulseConstraintModelTypes::all[constraint_type], |
|
74 |
PinocchioModelTypes::Talos); |
||
75 |
5 |
register_impulse_constraint_model_unit_tests( |
|
76 |
5 |
ImpulseConstraintModelTypes::all[constraint_type], |
|
77 |
PinocchioModelTypes::RandomHumanoid); |
||
78 |
5 |
if (ImpulseConstraintModelTypes::all[constraint_type] == |
|
79 |
ImpulseConstraintModelTypes:: |
||
80 |
✓✓✓✓ |
9 |
ConstraintModelResidualImpulseForceEquality || |
81 |
✓✓ | 4 |
ImpulseConstraintModelTypes::all[constraint_type] == |
82 |
ImpulseConstraintModelTypes:: |
||
83 |
ConstraintModelResidualImpulseFrictionConeInequality) { |
||
84 |
2 |
register_impulse_constraint_model_unit_tests( |
|
85 |
2 |
ImpulseConstraintModelTypes::all[constraint_type], |
|
86 |
PinocchioModelTypes::HyQ); |
||
87 |
} |
||
88 |
} |
||
89 |
|||
90 |
1 |
return true; |
|
91 |
} |
||
92 |
|||
93 |
1 |
int main(int argc, char **argv) { |
|
94 |
1 |
return ::boost::unit_test::unit_test_main(&init_function, argc, argv); |
|
95 |
} |
Generated by: GCOVR (Version 4.2) |