|
1 | 1 |
|
2 | 2 | #include <boost/test/unit_test.hpp> |
| 3 | +#include <vector> |
3 | 4 |
|
4 | 5 | #include "simple-mpc/interpolator.hxx" |
5 | 6 | #include "test_utils.cpp" |
@@ -137,46 +138,48 @@ BOOST_AUTO_TEST_CASE(interpolate) |
137 | 138 | BOOST_CHECK(vs2[0].isApprox(v_interp)); |
138 | 139 | } |
139 | 140 |
|
140 | | - // Test discrete interpolation method |
| 141 | + // Test contacts interpolation method |
141 | 142 | { |
142 | | - std::vector<Eigen::VectorXd> vs; |
143 | | - for (std::size_t i = 0; i < 4; i++) |
| 143 | + const size_t n_contacts = 4; |
| 144 | + |
| 145 | + std::vector<std::vector<bool>> cs; |
| 146 | + for (std::size_t i = 0; i < n_contacts; i++) |
144 | 147 | { |
145 | | - Eigen::VectorXd v0(model.nv); |
146 | | - v0.setRandom(); |
147 | | - vs.push_back(v0); |
| 148 | + std::vector<bool> c(n_contacts, false); |
| 149 | + c[i] = true; |
| 150 | + cs.push_back(c); |
148 | 151 | } |
149 | | - Eigen::VectorXd v_interp(model.nv); |
| 152 | + std::vector<bool> c_interp(n_contacts); |
150 | 153 |
|
151 | 154 | // First element |
152 | | - interpolator.interpolateDiscrete(-0.001, 0.1, vs, v_interp); |
153 | | - BOOST_CHECK(vs[0].isApprox(v_interp)); |
| 155 | + interpolator.interpolateContacts(-0.001, 0.1, cs, c_interp); |
| 156 | + BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[0].begin())); |
154 | 157 |
|
155 | | - interpolator.interpolateDiscrete(0, 0.1, vs, v_interp); |
156 | | - BOOST_CHECK(vs[0].isApprox(v_interp)); |
| 158 | + interpolator.interpolateContacts(0, 0.1, cs, c_interp); |
| 159 | + BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[0].begin())); |
157 | 160 |
|
158 | | - interpolator.interpolateDiscrete(0.001, 0.1, vs, v_interp); |
159 | | - BOOST_CHECK(vs[0].isApprox(v_interp)); |
| 161 | + interpolator.interpolateContacts(0.001, 0.1, cs, c_interp); |
| 162 | + BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[0].begin())); |
160 | 163 |
|
161 | 164 | // Middle element |
162 | | - interpolator.interpolateDiscrete(0.1, 0.1, vs, v_interp); |
163 | | - BOOST_CHECK(vs[1].isApprox(v_interp)); |
| 165 | + interpolator.interpolateContacts(0.1, 0.1, cs, c_interp); |
| 166 | + BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[1].begin())); |
164 | 167 |
|
165 | | - interpolator.interpolateDiscrete(0.15, 0.1, vs, v_interp); |
166 | | - BOOST_CHECK(vs[1].isApprox(v_interp)); |
| 168 | + interpolator.interpolateContacts(0.15, 0.1, cs, c_interp); |
| 169 | + BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[1].begin())); |
167 | 170 |
|
168 | | - interpolator.interpolateDiscrete(0.2, 0.1, vs, v_interp); |
169 | | - BOOST_CHECK(vs[2].isApprox(v_interp)); |
| 171 | + interpolator.interpolateContacts(0.2, 0.1, cs, c_interp); |
| 172 | + BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[2].begin())); |
170 | 173 |
|
171 | 174 | // Last element |
172 | | - interpolator.interpolateDiscrete(0.39, 0.1, vs, v_interp); |
173 | | - BOOST_CHECK(vs[3].isApprox(v_interp)); |
| 175 | + interpolator.interpolateContacts(0.39, 0.1, cs, c_interp); |
| 176 | + BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[3].begin())); |
174 | 177 |
|
175 | | - interpolator.interpolateDiscrete(0.4, 0.1, vs, v_interp); |
176 | | - BOOST_CHECK(vs[3].isApprox(v_interp)); |
| 178 | + interpolator.interpolateContacts(0.4, 0.1, cs, c_interp); |
| 179 | + BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[3].begin())); |
177 | 180 |
|
178 | | - interpolator.interpolateDiscrete(0.5, 0.1, vs, v_interp); |
179 | | - BOOST_CHECK(vs[3].isApprox(v_interp)); |
| 181 | + interpolator.interpolateContacts(0.5, 0.1, cs, c_interp); |
| 182 | + BOOST_CHECK(std::equal(c_interp.begin(), c_interp.end(), cs[3].begin())); |
180 | 183 | } |
181 | 184 | } |
182 | 185 |
|
|
0 commit comments