GCC Code Coverage Report


Directory: ./
File: unittest/test_constraint_manager.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 304 304 100.0%
Branches: 649 1282 50.6%

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 "crocoddyl/core/actions/lqr.hpp"
13 #include "crocoddyl/multibody/data/multibody.hpp"
14 #include "factory/constraint.hpp"
15 #include "unittest_common.hpp"
16
17 using namespace boost::unit_test;
18 using namespace crocoddyl::unittest;
19
20 //----------------------------------------------------------------------------//
21
22 3 void test_constructor(StateModelTypes::Type state_type) {
23 // Setup the test
24
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 StateModelFactory state_factory;
25
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::ConstraintModelManager model(state_factory.create(state_type));
26
27 // Run the print function
28
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 std::ostringstream tmp;
29
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 tmp << model;
30
31 // Test the initial size of the map
32
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 3 times.
3 BOOST_CHECK(model.get_constraints().size() == 0);
33 3 }
34
35 3 void test_addConstraint(StateModelTypes::Type state_type) {
36 // Setup the test
37
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 StateModelFactory state_factory;
38
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::ConstraintModelManager model(state_factory.create(state_type));
39
40 // add an active constraint
41 boost::shared_ptr<crocoddyl::ConstraintModelAbstract> rand_constraint_1 =
42
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 create_random_constraint(state_type);
43
2/4
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 model.addConstraint("random_constraint_1", rand_constraint_1);
44 3 std::size_t ng = rand_constraint_1->get_ng();
45 3 std::size_t nh = rand_constraint_1->get_nh();
46
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::size_t ng_T = rand_constraint_1->get_T_constraint() ? ng : 0;
47
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::size_t nh_T = rand_constraint_1->get_T_constraint() ? nh : 0;
48
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng() == ng);
49
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh() == nh);
50
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng_T() == ng_T);
51
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh_T() == nh_T);
52
53 // add an inactive constraint
54 boost::shared_ptr<crocoddyl::ConstraintModelAbstract> rand_constraint_2 =
55
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 create_random_constraint(state_type);
56
2/4
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 model.addConstraint("random_constraint_2", rand_constraint_2, false);
57
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng() == ng);
58
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh() == nh);
59
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng_T() == ng_T);
60
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh_T() == nh_T);
61
62 // change the random constraint 2 status
63
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 model.changeConstraintStatus("random_constraint_2", true);
64 3 ng += rand_constraint_2->get_ng();
65 3 nh += rand_constraint_2->get_nh();
66
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if (rand_constraint_2->get_T_constraint()) {
67 3 ng_T += rand_constraint_2->get_ng();
68 3 nh_T += rand_constraint_2->get_nh();
69 }
70
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng() == ng);
71
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh() == nh);
72
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng_T() == ng_T);
73
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh_T() == nh_T);
74
75 // change the random constraint 1 status
76
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 model.changeConstraintStatus("random_constraint_1", false);
77 3 ng -= rand_constraint_1->get_ng();
78 3 nh -= rand_constraint_1->get_nh();
79
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if (rand_constraint_1->get_T_constraint()) {
80 3 ng_T -= rand_constraint_1->get_ng();
81 3 nh_T -= rand_constraint_1->get_nh();
82 }
83
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng() == ng);
84
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh() == nh);
85
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng_T() == ng_T);
86
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh_T() == nh_T);
87 3 }
88
89 3 void test_addConstraint_error_message(StateModelTypes::Type state_type) {
90 // Setup the test
91
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 StateModelFactory state_factory;
92
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::ConstraintModelManager model(state_factory.create(state_type));
93
94 // create an constraint object
95 boost::shared_ptr<crocoddyl::ConstraintModelAbstract> rand_constraint =
96
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 create_random_constraint(state_type);
97
98 // add twice the same constraint object to the container
99
2/4
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 model.addConstraint("random_constraint", rand_constraint);
100
101 // test error message when we add a duplicate constraint
102
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 CaptureIOStream capture_ios;
103
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 capture_ios.beginCapture();
104
2/4
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 model.addConstraint("random_constraint", rand_constraint);
105
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 capture_ios.endCapture();
106
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 std::stringstream expected_buffer;
107 expected_buffer << "Warning: we couldn't add the random_constraint "
108
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 "constraint item, it already existed."
109
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 << std::endl;
110
8/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 3 times.
✗ Branch 18 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 3 times.
✗ Branch 25 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 3 times.
3 BOOST_CHECK(capture_ios.str() == expected_buffer.str());
111
112 // test error message when we change the constraint status of an inexistent
113 // constraint
114
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 capture_ios.beginCapture();
115
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 model.changeConstraintStatus("no_exist_constraint", true);
116
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 capture_ios.endCapture();
117
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 expected_buffer.clear();
118 expected_buffer << "Warning: we couldn't change the status of the "
119
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 "no_exist_constraint constraint item, it doesn't exist."
120
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 << std::endl;
121
8/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 3 times.
✗ Branch 18 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 3 times.
✗ Branch 25 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 3 times.
3 BOOST_CHECK(capture_ios.str() == expected_buffer.str());
122 3 }
123
124 3 void test_removeConstraint(StateModelTypes::Type state_type) {
125 // Setup the test
126
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 StateModelFactory state_factory;
127
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::ConstraintModelManager model(state_factory.create(state_type));
128
129 // add an active constraint
130 boost::shared_ptr<crocoddyl::ConstraintModelAbstract> rand_constraint =
131
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 create_random_constraint(state_type);
132
2/4
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 model.addConstraint("random_constraint", rand_constraint);
133 3 std::size_t ng = rand_constraint->get_ng();
134 3 std::size_t nh = rand_constraint->get_nh();
135
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::size_t ng_T = rand_constraint->get_T_constraint() ? ng : 0;
136
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::size_t nh_T = rand_constraint->get_T_constraint() ? nh : 0;
137
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng() == ng);
138
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh() == nh);
139
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng_T() == ng_T);
140
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh_T() == nh_T);
141
142 // remove the constraint
143
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 model.removeConstraint("random_constraint");
144
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng() == 0);
145
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh() == 0);
146
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_ng_T() == 0);
147
6/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
3 BOOST_CHECK(model.get_nh_T() == 0);
148 3 }
149
150 3 void test_removeConstraint_error_message(StateModelTypes::Type state_type) {
151 // Setup the test
152
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 StateModelFactory state_factory;
153
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::ConstraintModelManager model(state_factory.create(state_type));
154
155 // remove a none existing constraint form the container, we expect a cout
156 // message here
157
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 CaptureIOStream capture_ios;
158
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 capture_ios.beginCapture();
159
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 model.removeConstraint("random_constraint");
160
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 capture_ios.endCapture();
161
162 // Test that the error message is sent.
163
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 std::stringstream expected_buffer;
164 expected_buffer << "Warning: we couldn't remove the random_constraint "
165
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 "constraint item, it doesn't exist."
166
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 << std::endl;
167
8/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 3 times.
✗ Branch 18 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 3 times.
✗ Branch 25 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 3 times.
3 BOOST_CHECK(capture_ios.str() == expected_buffer.str());
168 3 }
169
170 3 void test_calc(StateModelTypes::Type state_type) {
171 // setup the test
172
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 StateModelFactory state_factory;
173
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::ConstraintModelManager model(state_factory.create(state_type));
174 // create the corresponding data object
175 const boost::shared_ptr<crocoddyl::StateMultibody>& state =
176 3 boost::static_pointer_cast<crocoddyl::StateMultibody>(model.get_state());
177 3 pinocchio::Model& pinocchio_model = *state->get_pinocchio().get();
178
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 pinocchio::Data pinocchio_data(pinocchio_model);
179
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 crocoddyl::DataCollectorMultibody shared_data(&pinocchio_data);
180
181 // create and add some constraint objects
182 3 std::vector<boost::shared_ptr<crocoddyl::ConstraintModelAbstract> > models;
183 3 std::vector<boost::shared_ptr<crocoddyl::ConstraintDataAbstract> > datas;
184
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 for (std::size_t i = 0; i < 5; ++i) {
185
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
15 std::ostringstream os;
186
2/4
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
15 os << "random_constraint_" << i;
187 const boost::shared_ptr<crocoddyl::ConstraintModelAbstract>& m =
188
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
15 create_random_constraint(state_type);
189
2/4
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
15 model.addConstraint(os.str(), m, 1.);
190
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
15 models.push_back(m);
191
2/4
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
15 datas.push_back(m->createData(&shared_data));
192 15 }
193
194 // create the data of the constraint sum
195 const boost::shared_ptr<crocoddyl::ConstraintDataManager>& data =
196
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 model.createData(&shared_data);
197
198 // compute the constraint sum data for the case when all constraints are
199 // defined as active
200
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 const Eigen::VectorXd& x1 = state->rand();
201
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 const Eigen::VectorXd& u1 = Eigen::VectorXd::Random(model.get_nu());
202
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data,
203 x1);
204
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
3 model.calc(data, x1, u1);
205
206 // check the constraint against single constraint computations
207 3 std::size_t ng_i = 0;
208 3 std::size_t nh_i = 0;
209
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 Eigen::VectorXd g = Eigen::VectorXd::Zero(model.get_ng());
210
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 Eigen::VectorXd h = Eigen::VectorXd::Zero(model.get_nh());
211
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 for (std::size_t i = 0; i < 5; ++i) {
212
3/6
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 15 times.
✗ Branch 11 not taken.
15 models[i]->calc(datas[i], x1, u1);
213 15 const std::size_t ng = models[i]->get_ng();
214 15 const std::size_t nh = models[i]->get_nh();
215
2/4
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
15 g.segment(ng_i, ng) = datas[i]->g;
216
2/4
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
15 h.segment(nh_i, nh) = datas[i]->h;
217 15 ng_i += ng;
218 15 nh_i += nh;
219 }
220
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->g.isApprox(g, 1e-9));
221
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->h.isApprox(h, 1e-9));
222 3 }
223
224 3 void test_calcDiff(StateModelTypes::Type state_type) {
225 // setup the test
226
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 StateModelFactory state_factory;
227
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::ConstraintModelManager model(state_factory.create(state_type));
228 // create the corresponding data object
229 const boost::shared_ptr<crocoddyl::StateMultibody>& state =
230 3 boost::static_pointer_cast<crocoddyl::StateMultibody>(model.get_state());
231 3 pinocchio::Model& pinocchio_model = *state->get_pinocchio().get();
232
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 pinocchio::Data pinocchio_data(pinocchio_model);
233
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 crocoddyl::DataCollectorMultibody shared_data(&pinocchio_data);
234
235 // create and add some constraint objects
236 3 std::vector<boost::shared_ptr<crocoddyl::ConstraintModelAbstract> > models;
237 3 std::vector<boost::shared_ptr<crocoddyl::ConstraintDataAbstract> > datas;
238
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 for (std::size_t i = 0; i < 5; ++i) {
239
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
15 std::ostringstream os;
240
2/4
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
15 os << "random_constraint_" << i;
241 const boost::shared_ptr<crocoddyl::ConstraintModelAbstract>& m =
242
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
15 create_random_constraint(state_type);
243
2/4
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
15 model.addConstraint(os.str(), m, 1.);
244
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
15 models.push_back(m);
245
2/4
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
15 datas.push_back(m->createData(&shared_data));
246 15 }
247
248 // create the data of the constraint sum
249 const boost::shared_ptr<crocoddyl::ConstraintDataManager>& data =
250
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 model.createData(&shared_data);
251
252 // compute the constraint sum data for the case when all constraints are
253 // defined as active
254
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 Eigen::VectorXd x1 = state->rand();
255
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 const Eigen::VectorXd u1 = Eigen::VectorXd::Random(model.get_nu());
256
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data,
257 x1);
258
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
3 model.calc(data, x1, u1);
259
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
3 model.calcDiff(data, x1, u1);
260
261 // check the constraint against single constraint computations
262 3 std::size_t ng_i = 0;
263 3 std::size_t nh_i = 0;
264 3 const std::size_t ndx = state->get_ndx();
265 3 const std::size_t nu = model.get_nu();
266
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 Eigen::VectorXd g = Eigen::VectorXd::Zero(model.get_ng());
267
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 Eigen::VectorXd h = Eigen::VectorXd::Zero(model.get_nh());
268
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 Eigen::MatrixXd Gx = Eigen::MatrixXd::Zero(model.get_ng(), ndx);
269
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 Eigen::MatrixXd Gu = Eigen::MatrixXd::Zero(model.get_ng(), nu);
270
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 Eigen::MatrixXd Hx = Eigen::MatrixXd::Zero(model.get_nh(), ndx);
271
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 Eigen::MatrixXd Hu = Eigen::MatrixXd::Zero(model.get_nh(), nu);
272
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 for (std::size_t i = 0; i < 5; ++i) {
273
3/6
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 15 times.
✗ Branch 11 not taken.
15 models[i]->calc(datas[i], x1, u1);
274
3/6
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 15 times.
✗ Branch 11 not taken.
15 models[i]->calcDiff(datas[i], x1, u1);
275 15 const std::size_t ng = models[i]->get_ng();
276 15 const std::size_t nh = models[i]->get_nh();
277
2/4
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
15 g.segment(ng_i, ng) = datas[i]->g;
278
2/4
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
15 h.segment(nh_i, nh) = datas[i]->h;
279
2/4
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
15 Gx.block(ng_i, 0, ng, ndx) = datas[i]->Gx;
280
2/4
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
15 Gu.block(ng_i, 0, ng, nu) = datas[i]->Gu;
281
2/4
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
15 Hx.block(nh_i, 0, nh, ndx) = datas[i]->Hx;
282
2/4
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
15 Hu.block(nh_i, 0, nh, nu) = datas[i]->Hu;
283 15 ng_i += ng;
284 15 nh_i += nh;
285 }
286
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->g.isApprox(g, 1e-9));
287
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->h.isApprox(h, 1e-9));
288
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->Gx.isApprox(Gx, 1e-9));
289
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->Gu.isApprox(Gu, 1e-9));
290
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->Hx.isApprox(Hx, 1e-9));
291
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->Hu.isApprox(Hu, 1e-9));
292
293
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 x1 = state->rand();
294
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::unittest::updateAllPinocchio(&pinocchio_model, &pinocchio_data,
295 x1);
296
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 data->resize(&model, false);
297
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 model.calc(data, x1);
298
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 model.calcDiff(data, x1);
299
300 3 const std::size_t ng_T = model.get_ng_T();
301 3 const std::size_t nh_T = model.get_nh_T();
302 3 ng_i = 0;
303 3 nh_i = 0;
304
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 g.conservativeResize(ng_T);
305
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 h.conservativeResize(nh_T);
306
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 Gx.conservativeResize(ng_T, ndx);
307
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 Gu.conservativeResize(ng_T, nu);
308
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 Hx.conservativeResize(nh_T, ndx);
309
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 Hu.conservativeResize(nh_T, nu);
310
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 for (std::size_t i = 0; i < 5; ++i) {
311
2/2
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 3 times.
15 if (models[i]->get_T_constraint()) {
312
2/4
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
12 models[i]->calc(datas[i], x1);
313
2/4
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
12 models[i]->calcDiff(datas[i], x1);
314 12 const std::size_t ng = models[i]->get_ng();
315 12 const std::size_t nh = models[i]->get_nh();
316
2/4
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
12 g.segment(ng_i, ng) = datas[i]->g;
317
2/4
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
12 h.segment(nh_i, nh) = datas[i]->h;
318
2/4
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
12 Gx.block(ng_i, 0, ng, ndx) = datas[i]->Gx;
319
2/4
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
12 Gu.block(ng_i, 0, ng, nu) = datas[i]->Gu;
320
2/4
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
12 Hx.block(nh_i, 0, nh, ndx) = datas[i]->Hx;
321
2/4
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
12 Hu.block(nh_i, 0, nh, nu) = datas[i]->Hu;
322 12 ng_i += ng;
323 12 nh_i += nh;
324 }
325 }
326
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->g.isApprox(g, 1e-9));
327
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->h.isApprox(h, 1e-9));
328
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->Gx.isApprox(Gx, 1e-9));
329
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
3 BOOST_CHECK(data->Hx.isApprox(Hx, 1e-9));
330 3 }
331
332 3 void test_get_constraints(StateModelTypes::Type state_type) {
333 // setup the test
334
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 StateModelFactory state_factory;
335
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 crocoddyl::ConstraintModelManager model(state_factory.create(state_type));
336 // create the corresponding data object
337 const boost::shared_ptr<crocoddyl::StateMultibody>& state =
338 3 boost::static_pointer_cast<crocoddyl::StateMultibody>(model.get_state());
339
1/2
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 pinocchio::Data pinocchio_data(*state->get_pinocchio().get());
340
341 // create and add some contact objects
342
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 for (unsigned i = 0; i < 5; ++i) {
343
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
15 std::ostringstream os;
344
2/4
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
15 os << "random_constraint_" << i;
345
3/6
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 15 times.
✗ Branch 8 not taken.
15 model.addConstraint(os.str(), create_random_constraint(state_type), 1.);
346 15 }
347
348 // get the contacts
349 const crocoddyl::ConstraintModelManager::ConstraintModelContainer&
350 3 constraints = model.get_constraints();
351
352 // test
353 crocoddyl::ConstraintModelManager::ConstraintModelContainer::const_iterator
354 3 it_m,
355 3 end_m;
356 unsigned i;
357 3 for (i = 0, it_m = constraints.begin(), end_m = constraints.end();
358
2/2
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 3 times.
18 it_m != end_m; ++it_m, ++i) {
359
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
15 std::ostringstream os;
360
2/4
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
15 os << "random_constraint_" << i;
361
7/14
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 15 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 15 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 15 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 15 times.
✗ Branch 23 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 15 times.
15 BOOST_CHECK(it_m->first == os.str());
362 15 }
363 3 }
364
365 3 void test_shareMemory(StateModelTypes::Type state_type) {
366 // setup the test
367
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 StateModelFactory state_factory;
368 const boost::shared_ptr<crocoddyl::StateAbstract> state =
369
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 state_factory.create(state_type);
370
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 crocoddyl::ConstraintModelManager constraint_model(state);
371 3 crocoddyl::DataCollectorAbstract shared_data;
372 const boost::shared_ptr<crocoddyl::ConstraintDataManager>& constraint_data =
373
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 constraint_model.createData(&shared_data);
374
375 3 std::size_t ng = state->get_ndx();
376 3 std::size_t nh = state->get_ndx();
377 3 const std::size_t ndx = state->get_ndx();
378 3 const std::size_t nu = constraint_model.get_nu();
379
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 crocoddyl::ActionModelLQR action_model(ndx, nu);
380 const boost::shared_ptr<crocoddyl::ActionDataAbstract>& action_data =
381
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 action_model.createData();
382
383
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 action_data->h.resize(nh);
384
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 action_data->g.resize(ng);
385
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 action_data->Gx.resize(ng, ndx);
386
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 action_data->Gu.resize(ng, nu);
387
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 action_data->Hx.resize(nh, ndx);
388
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 action_data->Hu.resize(nh, nu);
389
1/2
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
3 constraint_data->shareMemory(action_data.get());
390
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 constraint_data->h = Eigen::VectorXd::Random(nh);
391
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 constraint_data->g = Eigen::VectorXd::Random(ng);
392
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 constraint_data->Gx = Eigen::MatrixXd::Random(ng, ndx);
393
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 constraint_data->Gu = Eigen::MatrixXd::Random(ng, nu);
394
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 constraint_data->Hx = Eigen::MatrixXd::Random(nh, ndx);
395
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 constraint_data->Hu = Eigen::MatrixXd::Random(nh, nu);
396
397 // check that the data has been shared
398
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->g.isApprox(constraint_data->g, 1e-9));
399
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->h.isApprox(constraint_data->h, 1e-9));
400
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->Gx.isApprox(constraint_data->Gx, 1e-9));
401
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->Gu.isApprox(constraint_data->Gu, 1e-9));
402
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->Hx.isApprox(constraint_data->Hx, 1e-9));
403
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->Hu.isApprox(constraint_data->Hu, 1e-9));
404
405 // let's now resize the data
406
1/2
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
3 constraint_data->resize(&action_model, action_data.get());
407
408 // check that the shared data has been resized
409
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->g.isApprox(constraint_data->g, 1e-9));
410
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->h.isApprox(constraint_data->h, 1e-9));
411
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->Gx.isApprox(constraint_data->Gx, 1e-9));
412
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->Gu.isApprox(constraint_data->Gu, 1e-9));
413
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->Hx.isApprox(constraint_data->Hx, 1e-9));
414
7/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
3 BOOST_CHECK(action_data->Hu.isApprox(constraint_data->Hu, 1e-9));
415 3 }
416
417 //----------------------------------------------------------------------------//
418
419 3 void register_unit_tests(StateModelTypes::Type state_type) {
420
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 boost::test_tools::output_test_stream test_name;
421 test_name << "test_ConstraintModelManager"
422
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
3 << "_" << state_type;
423
4/8
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
3 std::cout << "Running " << test_name.str() << std::endl;
424
4/8
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
3 test_suite* ts = BOOST_TEST_SUITE(test_name.str());
425
5/10
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 ts->add(BOOST_TEST_CASE(boost::bind(&test_constructor, state_type)));
426
5/10
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 ts->add(BOOST_TEST_CASE(boost::bind(&test_addConstraint, state_type)));
427
5/10
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 ts->add(BOOST_TEST_CASE(
428 boost::bind(&test_addConstraint_error_message, state_type)));
429
5/10
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 ts->add(BOOST_TEST_CASE(boost::bind(&test_removeConstraint, state_type)));
430
5/10
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 ts->add(BOOST_TEST_CASE(
431 boost::bind(&test_removeConstraint_error_message, state_type)));
432
5/10
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 ts->add(BOOST_TEST_CASE(boost::bind(&test_calc, state_type)));
433
5/10
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 ts->add(BOOST_TEST_CASE(boost::bind(&test_calcDiff, state_type)));
434
5/10
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 ts->add(BOOST_TEST_CASE(boost::bind(&test_get_constraints, state_type)));
435
5/10
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 ts->add(BOOST_TEST_CASE(boost::bind(&test_shareMemory, state_type)));
436
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 framework::master_test_suite().add(ts);
437 3 }
438
439 1 bool init_function() {
440 1 register_unit_tests(StateModelTypes::StateMultibody_TalosArm);
441 1 register_unit_tests(StateModelTypes::StateMultibody_HyQ);
442 1 register_unit_tests(StateModelTypes::StateMultibody_Talos);
443 1 return true;
444 }
445
446 1 int main(int argc, char** argv) {
447 1 return ::boost::unit_test::unit_test_main(&init_function, argc, argv);
448 }
449