Skip to content

Commit

Permalink
tests: random_matrices sparse version
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-weber committed Jan 9, 2023
1 parent ef779e6 commit fc636b3
Show file tree
Hide file tree
Showing 2 changed files with 946 additions and 517 deletions.
40 changes: 14 additions & 26 deletions scripts/lpgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <catch2/catch.hpp>
#include <solp.h>
#include <Eigen/Dense>
#include <iostream>
#include "helpers.h"
TEST_CASE("random matrices") {
'''
types = {
Expand Down Expand Up @@ -61,31 +61,19 @@ def print_cpp_tests(outfile, cases):
'''.format(a = Astr,
c = eigen_comma(c)))


if case['type'] == 'valid':
f.write('''res = solp::solve(c, A);
sol << {c};
resx = Eigen::Map<Eigen::VectorXd>(res.x.data(), res.x.size());
CHECK(sol.isApprox(resx, 1.0e-8));
'''.format(c = eigen_comma(x)))
elif case['type'] == 'unbounded':
f.write('''CHECK_THROWS(solp::solve(c, A));
try {
solp::solve(c, A);
} catch(const solp::exception &e) {
CHECK(e.status == solp::exception::type::unbounded);
}
''')
elif case['type'] == 'infeasible':
f.write('''CHECK_THROWS(solp::solve(c, A));
try {
solp::solve(c, A);
} catch(const solp::exception &e) {
CHECK(e.status == solp::exception::type::infeasible);
}
''')

for A in ['A', 'convert_to_sparse(A)']:

if case['type'] == 'valid':
f.write('''res = solp::solve(c, {A});
CHECK_THAT(res.x, Catch::Matchers::Approx(std::vector{{{solution}}}).margin(1e-10));
'''.format(A = A, solution = eigen_comma(x)))
elif case['type'] == 'unbounded':
f.write('''CHECK_THROWS_MATCHES(solp::solve(c, {A}), solp::exception, MatchSolpException(solp::exception::type::unbounded));
'''.format(A=A))
elif case['type'] == 'infeasible':
f.write('''CHECK_THROWS_MATCHES(solp::solve(c, {A}), solp::exception, MatchSolpException(solp::exception::type::infeasible));
'''.format(A=A))


f.write('}\n')
Expand Down
Loading

0 comments on commit fc636b3

Please sign in to comment.