Skip to content

Commit

Permalink
add test for bad inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
bodono committed Oct 1, 2021
1 parent 7bed3c6 commit c358d62
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/problems/test_fails.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "glbopts.h"
#include "minunit.h"
#include "problem_utils.h"
#include "scs.h"
#include "util.h"

static const char *test_fails(void) {
scs_printf("Testing that SCS handles bad inputs correctly:");

ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
ScsSolution *sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
ScsSolution *opt_sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
ScsInfo info = {0};
scs_float p_f = 0.1;
int seed = 1234;
scs_int n = 1;
scs_int m = 3;
scs_int col_nnz = (scs_int)ceil(sqrt(n));
scs_int nnz = n * col_nnz;
scs_int exitflag;

k->z = (scs_int)floor(m * p_f);
k->l = m - k->z;

d->m = m;
d->n = n;
gen_random_prob_data(nnz, col_nnz, d, k, opt_sol, seed);
SCS(set_default_settings)(stgs);

/* TODO test more failure modes */
stgs->eps_abs = -1;

exitflag = scs(d, k, stgs, sol, &info);

mu_assert("test_fails: SCS failed to produce outputflag SCS_FAILED",
exitflag == SCS_FAILED);
SCS(free_data)(d, k, stgs);
SCS(free_sol)(sol);
SCS(free_sol)(opt_sol);
return 0;
}
3 changes: 3 additions & 0 deletions test/run_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
#include "problems/random_prob.h"
#include "problems/rob_gauss_cov_est.h"
#include "problems/small_lp.h"
#include "problems/test_fails.h"
#include "problems/unbounded_tiny_qp.h"

int tests_run = 0;

static const char *all_tests(void) {
scs_printf("test_fails\n");
mu_run_test(test_fails);
scs_printf("degenerate\n");
mu_run_test(degenerate);
scs_printf("small_lp\n");
Expand Down

0 comments on commit c358d62

Please sign in to comment.