Skip to content

Commit

Permalink
Merge pull request #133 from nikalra/master
Browse files Browse the repository at this point in the history
Updated tests to be C++ compliant
  • Loading branch information
gbanjac authored Apr 30, 2019
2 parents 7b33ad2 + f9ced43 commit c60bb3c
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 54 deletions.
12 changes: 6 additions & 6 deletions tests/basic_qp/test_basic_qp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "basic_qp/data.h"


static char* test_basic_qp_solve()
static const char* test_basic_qp_solve()
{
// Problem settings
OSQPSettings *settings = (OSQPSettings *)c_malloc(sizeof(OSQPSettings));
Expand Down Expand Up @@ -187,7 +187,7 @@ static char* test_basic_qp_solve_pardiso()
}
#endif

static char* test_basic_qp_update()
static const char* test_basic_qp_update()
{
// Problem settings
OSQPSettings *settings = (OSQPSettings *)c_malloc(sizeof(OSQPSettings));
Expand Down Expand Up @@ -296,7 +296,7 @@ static char* test_basic_qp_update()
return 0;
}

static char* test_basic_qp_check_termination()
static const char* test_basic_qp_check_termination()
{
// Problem settings
OSQPSettings *settings = (OSQPSettings *)c_malloc(sizeof(OSQPSettings));
Expand Down Expand Up @@ -369,7 +369,7 @@ static char* test_basic_qp_check_termination()
return 0;
}

static char* test_basic_qp_update_rho()
static const char* test_basic_qp_update_rho()
{
// Problem settings
OSQPSettings *settings = (OSQPSettings *)c_malloc(sizeof(OSQPSettings));
Expand Down Expand Up @@ -497,7 +497,7 @@ static char* test_basic_qp_update_rho()
return 0;
}

static char* test_basic_qp_time_limit()
static const char* test_basic_qp_time_limit()
{
// Problem settings
OSQPSettings *settings = (OSQPSettings *)c_malloc(sizeof(OSQPSettings));
Expand Down Expand Up @@ -558,7 +558,7 @@ static char* test_basic_qp_time_limit()
return 0;
}

static char* test_basic_qp()
static const char* test_basic_qp()
{
mu_run_test(test_basic_qp_solve);
#ifdef ENABLE_MKL_PARDISO
Expand Down
6 changes: 3 additions & 3 deletions tests/basic_qp2/test_basic_qp2.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "basic_qp2/data.h"


static char* test_basic_qp2_solve()
static const char* test_basic_qp2_solve()
{
/* local variables */
c_int exitflag = 0; // No errors
Expand Down Expand Up @@ -145,7 +145,7 @@ static char* test_basic_qp2_solve_pardiso()
}
#endif

static char* test_basic_qp2_update()
static const char* test_basic_qp2_update()
{
/* local variables */
c_int exitflag = 0; // No errors
Expand Down Expand Up @@ -221,7 +221,7 @@ static char* test_basic_qp2_update()
return 0;
}

static char* test_basic_qp2()
static const char* test_basic_qp2()
{
mu_run_test(test_basic_qp2_solve);
#ifdef ENABLE_MKL_PARDISO
Expand Down
14 changes: 7 additions & 7 deletions tests/lin_alg/test_lin_alg.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "lin_alg/data.h"

static char* test_constr_sparse_mat() {
static const char* test_constr_sparse_mat() {
c_float *Adns; // Conversion to dense matrix

lin_alg_sols_data *data = generate_problem_lin_alg_sols_data();
Expand All @@ -25,7 +25,7 @@ static char* test_constr_sparse_mat() {
return 0;
}

static char* test_vec_operations() {
static const char* test_vec_operations() {
c_float norm_inf, vecprod; // normInf;
c_float *ew_reciprocal;
c_float *add_scaled;
Expand Down Expand Up @@ -112,7 +112,7 @@ static char* test_vec_operations() {
return 0;
}

static char* test_mat_operations() {
static const char* test_mat_operations() {
csc *Ad, *dA; // Matrices used for tests
// csc *A_ewsq, *A_ewabs; // Matrices used for tests
c_int exitflag = 0;
Expand Down Expand Up @@ -170,7 +170,7 @@ static char* test_mat_operations() {
return 0;
}

static char* test_mat_vec_multiplication() {
static const char* test_mat_vec_multiplication() {
c_float *Ax, *ATy, *Px, *Ax_cum, *ATy_cum, *Px_cum;

lin_alg_sols_data *data = generate_problem_lin_alg_sols_data();
Expand Down Expand Up @@ -255,7 +255,7 @@ static char* test_mat_vec_multiplication() {
return 0;
}

static char* test_extract_upper_triangular() {
static const char* test_extract_upper_triangular() {
c_float *inf_norm_cols_test;
lin_alg_sols_data *data = generate_problem_lin_alg_sols_data();

Expand Down Expand Up @@ -285,7 +285,7 @@ static char* test_extract_upper_triangular() {
return 0;
}

static char* test_quad_form_upper_triang() {
static const char* test_quad_form_upper_triang() {
c_float quad_form_t;

lin_alg_sols_data *data = generate_problem_lin_alg_sols_data();
Expand All @@ -303,7 +303,7 @@ static char* test_quad_form_upper_triang() {
return 0;
}

static char* test_lin_alg()
static const char* test_lin_alg()
{
mu_run_test(test_constr_sparse_mat);
mu_run_test(test_vec_operations);
Expand Down
2 changes: 1 addition & 1 deletion tests/minunit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define mu_assert(message, test) \
do { if (!(test)) return message; } while (0)
#define mu_run_test(test) \
do { char *message = test(); tests_run++; \
do { const char *message = test(); tests_run++; \
if (message) return message; } while (0)
extern int tests_run;

Expand Down
6 changes: 3 additions & 3 deletions tests/non_cvx/test_non_cvx.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "non_cvx/data.h"


static char* test_non_cvx_solve()
static const char* test_non_cvx_solve()
{
/* local variables */
c_int exitflag = 0; // No errors
Expand Down Expand Up @@ -53,7 +53,7 @@ static char* test_non_cvx_solve()

// Compare objective values
mu_assert("Non Convex test solve: Error in objective value!",
work->info->obj_val == OSQP_NAN);
work->info->obj_val == OSQP_NAN);

// Clean workspace
osqp_cleanup(work);
Expand All @@ -66,7 +66,7 @@ static char* test_non_cvx_solve()
return 0;
}

static char* test_non_cvx()
static const char* test_non_cvx()
{
mu_run_test(test_non_cvx_solve);

Expand Down
4 changes: 2 additions & 2 deletions tests/osqp_tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
int tests_run = 0;


static char* all_tests() {
static const char* all_tests() {
mu_run_test(test_lin_alg);
mu_run_test(test_solve_linsys);
mu_run_test(test_basic_qp);
Expand All @@ -38,7 +38,7 @@ static char* all_tests() {
}

int main(void) {
char *result = all_tests();
const char *result = all_tests();

if (result != 0) {
printf("%s\n", result);
Expand Down
18 changes: 9 additions & 9 deletions tests/primal_dual_infeasibility/test_primal_dual_infeasibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "primal_dual_infeasibility/data.h"


static char* test_optimal()
static const char* test_optimal()
{
// Structures
OSQPWorkspace *work; // Workspace
Expand All @@ -18,7 +18,7 @@ static char* test_optimal()
data = generate_problem_primal_dual_infeasibility_sols_data();

// Populate problem data
problem = c_malloc(sizeof(OSQPData));
problem = (OSQPData*) c_malloc(sizeof(OSQPData));
problem->P = data->P;
problem->q = data->q;
problem->A = data->A12;
Expand Down Expand Up @@ -74,7 +74,7 @@ static char* test_optimal()
return 0;
}

static char* test_prim_infeas()
static const char* test_prim_infeas()
{
// Structures
OSQPWorkspace *work; // Workspace
Expand All @@ -86,7 +86,7 @@ static char* test_prim_infeas()
data = generate_problem_primal_dual_infeasibility_sols_data();

// Populate problem data
problem = c_malloc(sizeof(OSQPData));
problem = (OSQPData*) c_malloc(sizeof(OSQPData));
problem->P = data->P;
problem->q = data->q;
problem->A = data->A12;
Expand Down Expand Up @@ -126,7 +126,7 @@ static char* test_prim_infeas()
return 0;
}

static char* test_dual_infeas()
static const char* test_dual_infeas()
{
// Structures
OSQPWorkspace *work; // Workspace
Expand All @@ -138,7 +138,7 @@ static char* test_dual_infeas()
data = generate_problem_primal_dual_infeasibility_sols_data();

// Populate problem data
problem = c_malloc(sizeof(OSQPData));
problem = (OSQPData*) c_malloc(sizeof(OSQPData));
problem->P = data->P;
problem->q = data->q;
problem->A = data->A34;
Expand Down Expand Up @@ -178,7 +178,7 @@ static char* test_dual_infeas()
return 0;
}

static char* test_primal_dual_infeas()
static const char* test_primal_dual_infeas()
{
// Structures
OSQPWorkspace *work; // Workspace
Expand All @@ -190,7 +190,7 @@ static char* test_primal_dual_infeas()
data = generate_problem_primal_dual_infeasibility_sols_data();

// Populate problem data
problem = c_malloc(sizeof(OSQPData));
problem = (OSQPData*) c_malloc(sizeof(OSQPData));
problem->P = data->P;
problem->q = data->q;
problem->A = data->A34;
Expand Down Expand Up @@ -231,7 +231,7 @@ static char* test_primal_dual_infeas()
return 0;
}

static char* test_primal_dual_infeasibility()
static const char* test_primal_dual_infeasibility()
{
mu_run_test(test_optimal);
mu_run_test(test_prim_infeas);
Expand Down
4 changes: 2 additions & 2 deletions tests/primal_infeasibility/test_primal_infeasibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "primal_infeasibility/data.h"


static char* test_primal_infeasible_qp_solve()
static const char* test_primal_infeasible_qp_solve()
{
// Problem settings
OSQPSettings *settings = (OSQPSettings *)c_malloc(sizeof(OSQPSettings));
Expand Down Expand Up @@ -58,7 +58,7 @@ static char* test_primal_infeasible_qp_solve()
return 0;
}

static char* test_primal_infeasibility()
static const char* test_primal_infeasibility()
{
mu_run_test(test_primal_infeasible_qp_solve);

Expand Down
6 changes: 3 additions & 3 deletions tests/solve_linsys/test_solve_linsys.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "solve_linsys/data.h"


static char* test_solveKKT() {
static const char* test_solveKKT() {
c_int m, exitflag = 0;
c_float *rho_vec;
LinSysSolver *p; // Private structure to form KKT factorization
Expand All @@ -22,7 +22,7 @@ static char* test_solveKKT() {

// Set rho_vec
m = data->test_solve_KKT_A->m;
rho_vec = c_calloc(m, sizeof(c_float));
rho_vec = (c_float*) c_calloc(m, sizeof(c_float));
vec_add_scalar(rho_vec, settings->rho, m);

// Form and factorize KKT matrix
Expand Down Expand Up @@ -112,7 +112,7 @@ static char* test_solveKKT_pardiso() {
}
#endif

static char* test_solve_linsys()
static const char* test_solve_linsys()
{
mu_run_test(test_solveKKT);
#ifdef ENABLE_MKL_PARDISO
Expand Down
4 changes: 2 additions & 2 deletions tests/unconstrained/test_unconstrained.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "unconstrained/data.h"


static char* test_unconstrained_solve()
static const char* test_unconstrained_solve()
{
/* local variables */
c_int exitflag = 0; // No errors
Expand Down Expand Up @@ -62,7 +62,7 @@ static char* test_unconstrained_solve()
return 0;
}

static char* test_unconstrained()
static const char* test_unconstrained()
{
mu_run_test(test_unconstrained_solve);

Expand Down
Loading

0 comments on commit c60bb3c

Please sign in to comment.