SuperSCS  1.3.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros | Typedefs | Functions | Variables
unit_test_util.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "glbopts.h"
#include <math.h>
#include "linAlg.h"

Go to the source code of this file.

Macros

#define true   1
 
#define false   0
 
#define TEST_SUCCESS   0
 
#define TEST_FAILURE   1
 
#define MESSAGE_OK   "OK"
 
#define TEST_PASS_FLAG   "\x1B[92m[PASS]\x1B[39m "
 
#define TEST_FAIL_FLAG   "\x1B[31m<FAIL>\x1B[39m "
 
#define TEST_MESSAGE_BUFF_SIZE   500
 
#define TEST_ERROR_MESSAGE_SIZE   100
 
#define FAIL_WITH_MESSAGE(str, message)
 
#define ASSERT_TRUE_OR_FAIL(p, str, message)
 
#define ASSERT_EQUAL_INT_OR_FAIL(val, expected, str, message)
 
#define ASSERT_EQUAL_FLOAT_OR_FAIL(val, expected, tol, str, message)
 
#define ASSERT_EQUAL_ARRAY_OR_FAIL(val, expected, len, tol, str, message)
 
#define ASSERT_EQUAL_ARRAY_INT_OR_FAIL(val, expected, len, str, message)
 
#define SUCCEED(str)
 

Typedefs

typedef int bool
 
typedef bool(* unitTest_t )(char **)
 

Functions

bool scs_test (const unitTest_t ut, const char *name)
 
bool scs_assert_equals_int (const scs_int a, const scs_int b)
 
bool scs_assert_equals_float (const scs_float a, const scs_float b, const scs_float tol)
 
bool scs_assert_equals_array (const scs_float *a, const scs_float *b, scs_int n, const scs_float tol)
 
bool scs_assert_equals_array_int (const scs_int *a, const scs_int *b, scs_int n)
 

Variables

int number_of_assertions
 

Macro Definition Documentation

#define ASSERT_EQUAL_ARRAY_INT_OR_FAIL (   val,
  expected,
  len,
  str,
  message 
)
Value:
if (!scs_assert_equals_array_int((val),(expected),(len))){\
FAIL_WITH_MESSAGE((str), (message));\
}
bool scs_assert_equals_array_int(const scs_int *a, const scs_int *b, scs_int n)
#define FAIL_WITH_MESSAGE(str, message)
Definition: unit_test_util.h:72
int number_of_assertions
Definition: unit_test_util.h:60

Check whether two arrays are equal, or fail with a given message.

#define ASSERT_EQUAL_ARRAY_OR_FAIL (   val,
  expected,
  len,
  tol,
  str,
  message 
)
Value:
if (!scs_assert_equals_array((val),(expected),(len),(tol))){\
FAIL_WITH_MESSAGE((str), (message));\
}
bool scs_assert_equals_array(const scs_float *a, const scs_float *b, scs_int n, const scs_float tol)
#define FAIL_WITH_MESSAGE(str, message)
Definition: unit_test_util.h:72
int number_of_assertions
Definition: unit_test_util.h:60

Check whether two arrays are equal, or fail with a given message.

#define ASSERT_EQUAL_FLOAT_OR_FAIL (   val,
  expected,
  tol,
  str,
  message 
)
Value:
if (!scs_assert_equals_float((val), (expected), (tol))) {\
char error_msg[TEST_ERROR_MESSAGE_SIZE];\
sprintf(error_msg, "\n\tExpected: %g, Actual %g (tol=%g)", expected, val, tol);\
strncpy(buff, message, TEST_ERROR_MESSAGE_SIZE);\
strncat(buff, error_msg, TEST_ERROR_MESSAGE_SIZE);\
FAIL_WITH_MESSAGE((str), (buff)); \
}
#define TEST_ERROR_MESSAGE_SIZE
Definition: unit_test_util.h:68
bool scs_assert_equals_float(const scs_float a, const scs_float b, const scs_float tol)
#define FAIL_WITH_MESSAGE(str, message)
Definition: unit_test_util.h:72
int number_of_assertions
Definition: unit_test_util.h:60
#define TEST_MESSAGE_BUFF_SIZE
Definition: unit_test_util.h:67

Check whether two integers are equal, or fail with a given message.

#define ASSERT_EQUAL_INT_OR_FAIL (   val,
  expected,
  str,
  message 
)
Value:
if (!scs_assert_equals_int((val),(expected))) { \
{\
char error_msg[TEST_ERROR_MESSAGE_SIZE];\
sprintf(error_msg, "\n\tExpected: %d, Actual %d", expected, val);\
strncpy(buff, message, TEST_ERROR_MESSAGE_SIZE);\
strncat(buff, error_msg, TEST_ERROR_MESSAGE_SIZE);\
FAIL_WITH_MESSAGE((str), (buff)); \
}\
}
#define TEST_ERROR_MESSAGE_SIZE
Definition: unit_test_util.h:68
#define FAIL_WITH_MESSAGE(str, message)
Definition: unit_test_util.h:72
int number_of_assertions
Definition: unit_test_util.h:60
#define TEST_MESSAGE_BUFF_SIZE
Definition: unit_test_util.h:67
bool scs_assert_equals_int(const scs_int a, const scs_int b)

Check whether two integers are equal, or fail with a given message.

#define ASSERT_TRUE_OR_FAIL (   p,
  str,
  message 
)
Value:
if (!(p)) { \
FAIL_WITH_MESSAGE((str), (message));\
}
#define FAIL_WITH_MESSAGE(str, message)
Definition: unit_test_util.h:72
int number_of_assertions
Definition: unit_test_util.h:60
#define FAIL_WITH_MESSAGE (   str,
  message 
)
Value:
*str = (char*)(message);\
return TEST_FAILURE
#define TEST_FAILURE
Definition: unit_test_util.h:63

Fails with a given message.

#define false   0
#define MESSAGE_OK   "OK"

a message returned when a test is successful

#define SUCCEED (   str)
Value:
*str = (char*) MESSAGE_OK;\
return TEST_SUCCESS
#define MESSAGE_OK
Definition: unit_test_util.h:64
#define TEST_SUCCESS
Definition: unit_test_util.h:62

Succeed

#define TEST_ERROR_MESSAGE_SIZE   100
#define TEST_FAIL_FLAG   "\x1B[31m<FAIL>\x1B[39m "

flag for FAIL

#define TEST_FAILURE   1

test fails

#define TEST_MESSAGE_BUFF_SIZE   500
#define TEST_PASS_FLAG   "\x1B[92m[PASS]\x1B[39m "

flag for PASS

#define TEST_SUCCESS   0

test is successful

#define true   1

Typedef Documentation

typedef int bool
typedef bool(* unitTest_t)(char **)

Function template defining a unit test:

int myTestFunction(char**);

This type is a pointer to such a function which takes as an input argument a pointer to a string (char**) and returns a status code (either TEST_SUCCESS or TEST_FAILURE).

Function Documentation

bool scs_assert_equals_array ( const scs_float a,
const scs_float b,
scs_int  n,
const scs_float  tol 
)

Checks whether two arrays of float are equal, element-wise, up to a certain tolerance.

Parameters
afirst array
bsecond array
nlength of array
toltolerance
Returns
true is the two arrays are equal
bool scs_assert_equals_array_int ( const scs_int a,
const scs_int b,
scs_int  n 
)

Checks whether two arrays of float are equal, element-wise, up to a certain tolerance.

Parameters
afirst array
bsecond array
nlength of array
Returns
true is the two arrays are equal
bool scs_assert_equals_float ( const scs_float  a,
const scs_float  b,
const scs_float  tol 
)

Assert that two floats are equal up to a given tolerance.

Parameters
a
b
toltolerance
Returns
bool scs_assert_equals_int ( const scs_int  a,
const scs_int  b 
)

Assert that two integers are equal.

Parameters
a
b
Returns
bool scs_test ( const unitTest_t  ut,
const char *  name 
)

Tester function.

Parameters
utUnit Test function handle
nameName of the test
Returns
TEST_SUCCESS if the test succeeds and TEST_FAILURE if it fails.

Variable Documentation

int number_of_assertions