Skip to content

Commit

Permalink
[CI] Add unit test for QPSUT05
Browse files Browse the repository at this point in the history
OSQP is disabled for now: osqp/osqp-python#104
  • Loading branch information
stephane-caron committed Jan 31, 2023
1 parent 53fab7b commit 7522542
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def test_cond_sparse(self):
with self.assertRaises(ProblemError):
sparse.cond()

def test_check_matrix_shapes(self):
Problem(np.eye(1), np.ones(1))
Problem(np.array([1.0]), np.ones(1))

def test_check_vector_shapes(self):
Problem(np.eye(3), np.ones(shape=(3, 1)))
Problem(np.eye(3), np.ones(shape=(1, 3)))
Expand Down
34 changes: 34 additions & 0 deletions tests/test_solve_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
get_qpsut02,
get_qpsut03,
get_qpsut04,
get_qpsut05,
)


Expand Down Expand Up @@ -187,6 +188,32 @@ def test(self):

return test

@staticmethod
def get_test_qpsut05(solver: str):
"""
Get test function for the QPSUT04 problem.
Parameters
----------
solver :
Name of the solver to test.
Returns
-------
test : function
Test function for that solver.
"""

def test(self):
ref_solution = get_qpsut05()
problem = ref_solution.problem
solution = solve_problem(problem, solver=solver)
eps_abs = 2e-5 if solver == "ecos" else 1e-6
self.assertLess(norm(solution.x - ref_solution.x), eps_abs)
self.assertTrue(np.isfinite(solution.duality_gap()))

return test

@staticmethod
def get_test_maros_meszaros_qptest(solver):
"""
Expand Down Expand Up @@ -311,6 +338,13 @@ def test(self):
f"test_qpsut04_{solver}",
TestSolveProblem.get_test_qpsut04(solver),
)
if solver not in ["osqp", "qpswift"]:
# OSQP: see https://github.com/osqp/osqp-python/issues/104
setattr(
TestSolveProblem,
f"test_qpsut05_{solver}",
TestSolveProblem.get_test_qpsut05(solver),
)
if solver not in ["ecos", "qpswift"]:
# See https://github.com/stephane-caron/qpsolvers/issues/159
# See https://github.com/stephane-caron/qpsolvers/issues/160
Expand Down

0 comments on commit 7522542

Please sign in to comment.