GCC Code Coverage Report


Directory: ./
File: tests/eiquadprog-fast.cpp
Date: 2024-08-26 22:54:11
Exec Total Coverage
Lines: 261 261 100.0%
Branches: 676 1352 50.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2019 CNRS
3 //
4 // This file is part of eiquadprog.
5 //
6 // eiquadprog is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 //(at your option) any later version.
10
11 // eiquadprog is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with eiquadprog. If not, see <https://www.gnu.org/licenses/>.
18
19 #include "eiquadprog/eiquadprog-fast.hpp"
20
21 #include <Eigen/Core>
22 #include <boost/test/unit_test.hpp>
23 #include <iostream>
24
25 using namespace eiquadprog::solvers;
26
27 /**
28 * solves the problem
29 * min. 0.5 * x' Hess x + g0' x
30 * s.t. CE x + ce0 = 0
31 * CI x + ci0 >= 0
32 */
33
34 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
35
36 // min ||x||^2
37
38
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(test_unbiased) {
39
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 EiquadprogFast qp;
40
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.reset(2, 0, 0);
41
42
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Q(2, 2);
43
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q.setZero();
44
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(0, 0) = 1.0;
45
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(1, 1) = 1.0;
46
47
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd C(2);
48
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C.setZero();
49
50
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aeq(0, 2);
51
52
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Beq(0);
53
54
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aineq(0, 2);
55
56
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Bineq(0);
57
58
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd x(2);
59
60
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd solution(2);
61
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution.setZero();
62
63 2 double val = 0.0;
64
65 2 EiquadprogFast_status expected = EIQUADPROG_FAST_OPTIMAL;
66
67 EiquadprogFast_status status =
68
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
69
70
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
2 BOOST_CHECK_EQUAL(status, expected);
71
72
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
2 BOOST_CHECK_CLOSE(qp.getObjValue(), val, 1e-6);
73
74
7/14
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
2 BOOST_CHECK(x.isApprox(solution));
75 2 }
76
77 // min ||x-x_0||^2, x_0 = (1 1)^T
78
79
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(test_biased) {
80
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 EiquadprogFast qp;
81
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.reset(2, 0, 0);
82
83
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Q(2, 2);
84
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q.setZero();
85
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(0, 0) = 1.0;
86
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(1, 1) = 1.0;
87
88
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd C(2);
89
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C(0) = -1.;
90
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C(1) = -1.;
91
92
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aeq(0, 2);
93
94
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Beq(0);
95
96
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aineq(0, 2);
97
98
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Bineq(0);
99
100
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd x(2);
101
102
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd solution(2);
103
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution(0) = 1.;
104
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution(1) = 1.;
105
106 2 double val = -1.;
107
108 2 EiquadprogFast_status expected = EIQUADPROG_FAST_OPTIMAL;
109
110 EiquadprogFast_status status =
111
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
112
113
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
2 BOOST_CHECK_EQUAL(status, expected);
114
115
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
2 BOOST_CHECK_CLOSE(qp.getObjValue(), val, 1e-6);
116
117
7/14
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
2 BOOST_CHECK(x.isApprox(solution));
118 2 }
119
120 // min ||x||^2
121 // s.t.
122 // x[1] = 1 - x[0]
123
124
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(test_equality_constraints) {
125
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 EiquadprogFast qp;
126
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.reset(2, 1, 0);
127
128
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Q(2, 2);
129
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q.setZero();
130
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(0, 0) = 1.0;
131
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(1, 1) = 1.0;
132
133
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd C(2);
134
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C.setZero();
135
136
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aeq(1, 2);
137
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aeq(0, 0) = 1.;
138
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aeq(0, 1) = 1.;
139
140
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Beq(1);
141
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Beq(0) = -1.;
142
143
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aineq(0, 2);
144
145
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Bineq(0);
146
147
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd x(2);
148
149
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd solution(2);
150
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution(0) = 0.5;
151
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution(1) = 0.5;
152
153 2 double val = 0.25;
154
155 2 EiquadprogFast_status expected = EIQUADPROG_FAST_OPTIMAL;
156
157 EiquadprogFast_status status =
158
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
159
160
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
2 BOOST_CHECK_EQUAL(status, expected);
161
162
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
2 BOOST_CHECK_CLOSE(qp.getObjValue(), val, 1e-6);
163
164
7/14
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
2 BOOST_CHECK(x.isApprox(solution));
165 2 }
166
167 // min ||x||^2
168 // s.t.
169 // x[i] >= 1
170
171
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(test_inequality_constraints) {
172
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 EiquadprogFast qp;
173
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.reset(2, 0, 2);
174
175
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Q(2, 2);
176
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q.setZero();
177
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(0, 0) = 1.0;
178
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(1, 1) = 1.0;
179
180
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd C(2);
181
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C.setZero();
182
183
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aeq(0, 2);
184
185
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Beq(0);
186
187
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aineq(2, 2);
188
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq.setZero();
189
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(0, 0) = 1.;
190
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(1, 1) = 1.;
191
192
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Bineq(2);
193
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Bineq(0) = -1.;
194
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Bineq(1) = -1.;
195
196
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd x(2);
197
198
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd solution(2);
199
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution(0) = 1.;
200
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution(1) = 1.;
201
202 2 double val = 1.;
203
204 2 EiquadprogFast_status expected = EIQUADPROG_FAST_OPTIMAL;
205
206 EiquadprogFast_status status =
207
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
208
209
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
2 BOOST_CHECK_EQUAL(status, expected);
210
211
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
2 BOOST_CHECK_CLOSE(qp.getObjValue(), val, 1e-6);
212
213
7/14
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
2 BOOST_CHECK(x.isApprox(solution));
214 2 }
215
216 // min ||x-x_0||^2, x_0 = (1 1)^T
217 // s.t.
218 // x[1] = 5 - x[0]
219 // x[1] >= 3
220
221
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(test_full) {
222
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 EiquadprogFast qp;
223
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.reset(2, 1, 1);
224
225
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Q(2, 2);
226
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q.setZero();
227
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(0, 0) = 1.0;
228
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(1, 1) = 1.0;
229
230
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd C(2);
231
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C(0) = -1.;
232
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C(1) = -1.;
233
234
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aeq(1, 2);
235
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aeq(0, 0) = 1.;
236
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aeq(0, 1) = 1.;
237
238
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Beq(1);
239
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Beq(0) = -5.;
240
241
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aineq(1, 2);
242
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq.setZero();
243
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(0, 1) = 1.;
244
245
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Bineq(1);
246
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Bineq(0) = -3.;
247
248
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd x(2);
249
250
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd solution(2);
251
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution(0) = 2.;
252
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution(1) = 3.;
253
254 2 double val = 1.5;
255
256 2 EiquadprogFast_status expected = EIQUADPROG_FAST_OPTIMAL;
257
258 EiquadprogFast_status status =
259
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
260
261
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
2 BOOST_CHECK_EQUAL(status, expected);
262
263
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
2 BOOST_CHECK_CLOSE(qp.getObjValue(), val, 1e-6);
264
265
7/14
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
2 BOOST_CHECK(x.isApprox(solution));
266 2 }
267
268 // min ||x||^2
269 // s.t.
270 // x[0] = 1
271 // x[0] = -1
272
273
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(test_unfeasible_equalities) {
274
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 EiquadprogFast qp;
275
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.reset(2, 2, 0);
276
277
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Q(2, 2);
278
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q.setZero();
279
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(0, 0) = 1.0;
280
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(1, 1) = 1.0;
281
282
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd C(2);
283
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C.setZero();
284
285
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aeq(2, 2);
286
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aeq.setZero();
287
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aeq(0, 0) = 1.;
288
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aeq(1, 0) = 1.;
289
290
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Beq(2);
291
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Beq(0) = -1.;
292
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Beq(1) = 1.;
293
294
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aineq(0, 2);
295
296
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Bineq(0);
297
298
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd x(2);
299
300 2 EiquadprogFast_status expected = EIQUADPROG_FAST_REDUNDANT_EQUALITIES;
301
302 EiquadprogFast_status status =
303
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
304
305
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
2 BOOST_CHECK_EQUAL(status, expected);
306 2 }
307
308 // min ||x||^2
309 // s.t.
310 // x[0] >= 1
311 // x[0] <= -1
312 //
313 // correctly fails, but returns wrong error code
314
315
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(test_unfeasible_inequalities) {
316
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 EiquadprogFast qp;
317
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.reset(2, 0, 2);
318
319
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Q(2, 2);
320
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q.setZero();
321
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(0, 0) = 1.0;
322
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(1, 1) = 1.0;
323
324
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd C(2);
325
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C.setZero();
326
327
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aeq(0, 2);
328
329
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Beq(0);
330
331
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aineq(2, 2);
332
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq.setZero();
333
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(0, 0) = 1.;
334
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(1, 0) = -1.;
335
336
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Bineq(2);
337
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Bineq(0) = -1;
338
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Bineq(1) = -1;
339
340
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd x(2);
341
342 2 EiquadprogFast_status expected = EIQUADPROG_FAST_INFEASIBLE;
343
344 EiquadprogFast_status status =
345
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
346
347
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
2 BOOST_WARN_EQUAL(status, expected);
348
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
2 BOOST_CHECK(status != EIQUADPROG_FAST_OPTIMAL);
349 2 }
350
351 // min ||x-x_0||^2, x_0 = (1 1)^T
352 // s.t.
353 // x[1] = 1 - x[0]
354 // x[0] <= 0
355 // x[1] <= 0
356 //
357 // correctly fails, but returns wrong error code
358
359
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(test_unfeasible_constraints) {
360
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 EiquadprogFast qp;
361
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.reset(2, 1, 2);
362
363
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Q(2, 2);
364
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q.setZero();
365
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(0, 0) = 1.0;
366
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(1, 1) = 1.0;
367
368
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd C(2);
369
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C(0) = -1.;
370
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C(1) = -1.;
371
372
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aeq(1, 2);
373
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aeq(0, 0) = 1.;
374
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aeq(0, 1) = 1.;
375
376
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Beq(1);
377
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Beq(0) = -1.;
378
379
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aineq(2, 2);
380
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq.setZero();
381
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(0, 0) = -1.;
382
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(1, 1) = -1.;
383
384
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Bineq(2);
385
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Bineq.setZero();
386
387
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd x(2);
388
389 2 EiquadprogFast_status expected = EIQUADPROG_FAST_INFEASIBLE;
390
391 EiquadprogFast_status status =
392
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
393
394
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
2 BOOST_WARN_EQUAL(status, expected);
395
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
2 BOOST_CHECK(status != EIQUADPROG_FAST_OPTIMAL);
396 2 }
397
398 // min -||x||^2
399 // DOES NOT WORK!
400
401
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(test_unbounded) {
402
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 EiquadprogFast qp;
403
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.reset(2, 0, 0);
404
405
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Q(2, 2);
406
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q.setZero();
407
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(0, 0) = -1.0;
408
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(1, 1) = -1.0;
409
410
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd C(2);
411
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C.setZero();
412
413
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aeq(0, 2);
414
415
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Beq(0);
416
417
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aineq(0, 2);
418
419
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Bineq(0);
420
421
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd x(2);
422
423 2 EiquadprogFast_status expected = EIQUADPROG_FAST_UNBOUNDED;
424
425 EiquadprogFast_status status =
426
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
427
428
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
2 BOOST_WARN_EQUAL(status, expected);
429
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
2 BOOST_WARN(status != EIQUADPROG_FAST_OPTIMAL); // SHOULD pass!
430 2 }
431
432 // min -||x||^2
433 // s.t.
434 // 0<= x[0] <= 1
435 // 0<= x[1] <= 1
436 // DOES NOT WORK!
437
438
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(test_nonconvex) {
439
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 EiquadprogFast qp;
440
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.reset(2, 0, 4);
441
442
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Q(2, 2);
443
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q.setZero();
444
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(0, 0) = -1.0;
445
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Q(1, 1) = -1.0;
446
447
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd C(2);
448
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 C.setZero();
449
450
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aeq(0, 2);
451
452
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Beq(0);
453
454
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::MatrixXd Aineq(4, 2);
455
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq.setZero();
456
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(0, 0) = 1.;
457
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(1, 0) = -1.;
458
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(2, 1) = 1.;
459
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Aineq(3, 1) = -1.;
460
461
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd Bineq(4);
462
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Bineq(0) = 0.;
463
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Bineq(1) = 1.;
464
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Bineq(2) = 0.;
465
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Bineq(3) = 1.;
466
467
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd x(2);
468
469
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Eigen::VectorXd solution(2);
470
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution(0) = 1.;
471
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 solution(1) = 1.;
472
473 2 double val = -1.;
474
475 2 EiquadprogFast_status expected = EIQUADPROG_FAST_OPTIMAL;
476
477 EiquadprogFast_status status =
478
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
479
480
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
2 BOOST_CHECK_EQUAL(status, expected);
481
482
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
2 BOOST_WARN_CLOSE(qp.getObjValue(), val, 1e-6);
483
484
7/14
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
2 BOOST_WARN(x.isApprox(solution));
485 2 }
486
487 BOOST_AUTO_TEST_SUITE_END()
488