Skip to content

Commit

Permalink
Extend test_all_shapes unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-caron committed Sep 1, 2022
1 parent ef972ab commit 65c50e2
Showing 1 changed file with 51 additions and 15 deletions.
66 changes: 51 additions & 15 deletions tests/test_solve_qp.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def test(self):
cases = [
{"P": P, "q": q},
{"P": P, "q": q, "G": G, "h": h},
{"P": P, "q": q, "A": A, "b": b},
{"P": P, "q": q, "G": G[0], "h": h0},
{"P": P, "q": q, "A": A, "b": b},
{"P": P, "q": q, "A": A[0], "b": b0},
{"P": P, "q": q, "G": G, "h": h, "A": A, "b": b},
{"P": P, "q": q, "G": G[0], "h": h0, "A": A, "b": b},
Expand All @@ -211,39 +211,75 @@ def test(self):
{
"P": P,
"q": q,
"G": G[0],
"h": h0,
"A": A[0],
"b": b0,
"G": G,
"h": h,
"A": A,
"b": b,
"lb": lb,
"ub": None,
},
{
"P": P,
"q": q,
"G": G,
"h": h,
"A": A,
"b": b,
"lb": None,
"ub": ub,
},
{
"P": P,
"q": q,
"G": G,
"h": h,
"A": A,
"b": b,
"lb": lb,
"ub": ub,
},
{
"P": P,
"q": q,
"G": G,
"h": h,
"lb": lb,
"ub": None,
},
{
"P": P,
"q": q,
"G": G[0],
"h": h0,
"A": A[0],
"b": b0,
"G": G,
"h": h,
"lb": None,
"ub": ub,
},
{
"P": P,
"q": q,
"G": G[0],
"h": h0,
"A": A[0],
"b": b0,
"G": G,
"h": h,
"lb": lb,
"ub": ub,
},
]

for (i, test_case) in enumerate(cases):
test_comp = {
k: v.shape if v is not None else "None"
for k, v in test_case.items()
}
quadprog_solution = solve_qp(solver="quadprog", **test_case)
x = solve_qp(solver=solver, **test_case)
self.assertLess(norm(x - quadprog_solution), 2e-4)
self.assertIsNotNone(
quadprog_solution,
f"Baseline failed on parameters: {test_comp}",
)
solver_solution = solve_qp(solver=solver, **test_case)
self.assertLess(
norm(solver_solution - quadprog_solution),
2e-4,
f"Solver failed on parameters: {test_comp}",
)

return test

Expand Down

0 comments on commit 65c50e2

Please sign in to comment.