Skip to content

Commit 677a8f8

Browse files
committed
[unittest] [eiquadprog-rt] test_unbounded
1 parent fd86171 commit 677a8f8

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

unittest/eiquadprog-rt.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,78 @@ BOOST_AUTO_TEST_CASE(test_unfeasible_equalities) {
279279
BOOST_CHECK_EQUAL(status, expected);
280280
}
281281

282+
// min ||x||^2
283+
// s.t.
284+
// x[0] >= 1
285+
// x[0] <= -1
286+
//
287+
// correctly fails, but returns wrong error code
288+
289+
BOOST_AUTO_TEST_CASE(test_unfeasible_inequalities) {
290+
RtEiquadprog<2,0,2> qp;
291+
292+
RtMatrixX<2,2>::d Q;
293+
Q.setZero();
294+
Q(0, 0) = 1.0;
295+
Q(1, 1) = 1.0;
296+
297+
RtVectorX<2>::d C;
298+
C.setZero();
299+
300+
RtMatrixX<0,2>::d Aeq;
301+
302+
RtVectorX<0>::d Beq;
303+
304+
RtMatrixX<2,2>::d Aineq;
305+
Aineq.setZero();
306+
Aineq(0, 0) = 1.;
307+
Aineq(1, 0) = -1.;
308+
309+
RtVectorX<2>::d Bineq;
310+
Bineq(0) = -1;
311+
Bineq(1) = -1;
312+
313+
RtVectorX<2>::d x;
314+
315+
RtEiquadprog_status expected = RT_EIQUADPROG_INFEASIBLE;
316+
317+
RtEiquadprog_status status = qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
318+
319+
BOOST_WARN_EQUAL(status, expected);
320+
BOOST_CHECK(status != RT_EIQUADPROG_OPTIMAL);
321+
}
322+
323+
// min -||x||^2
324+
// DOES NOT WORK!
325+
326+
BOOST_AUTO_TEST_CASE(test_unbounded) {
327+
RtEiquadprog<2,0,0> qp;
328+
329+
RtMatrixX<2,2>::d Q;
330+
Q.setZero();
331+
Q(0, 0) = -1.0;
332+
Q(1, 1) = -1.0;
333+
334+
RtVectorX<2>::d C;
335+
C.setZero();
336+
337+
RtMatrixX<0,2>::d Aeq;
338+
339+
RtVectorX<0>::d Beq;
340+
341+
RtMatrixX<0,2>::d Aineq;
342+
343+
RtVectorX<0>::d Bineq;
344+
345+
RtVectorX<2>::d x;
346+
347+
RtEiquadprog_status expected = RT_EIQUADPROG_UNBOUNDED;
348+
349+
RtEiquadprog_status status = qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
350+
351+
BOOST_WARN_EQUAL(status, expected);
352+
BOOST_WARN(status != RT_EIQUADPROG_OPTIMAL); // SHOULD pass!
353+
}
354+
282355
BOOST_AUTO_TEST_SUITE_END ()
283356

0 commit comments

Comments
 (0)