Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
o2scl::test_mgr Class Reference

A class to manage testing and record success and failure. More...

#include <test_mgr.h>

Public Member Functions

 test_mgr (bool success_l=true, std::string last_fail_l="", int ntests_l=0, int output_level_l=1)
 Create a test_mgr object.
 
bool report () const
 Provide a report of all tests so far. More...
 
template<class vec_t , class data_t >
bool test_rel_nonzero_table (const table_units< vec_t > &result, const table_units< vec_t > &expected, data_t error, data_t zero_tol, std::string description)
 Compare entries in expected to see if they match those in table result. More...
 
Individual get and set methods
bool get_success () const
 Return true if all tests have succeeded.
 
std::string get_last_fail () const
 Return the last failure description.
 
int get_output_level () const
 Return the output level.
 
std::string get_last_fail ()
 Returns the description of the last test that failed.
 
void set_output_level (int l)
 Set the output level. More...
 
int get_ntests () const
 Return the number of tests performed so far.
 
Main testing methods
template<class data_t >
bool test_rel (data_t result, data_t expected, data_t rel_error, std::string description)
 Test for $|\mathrm{result}-\mathrm{expected}|/ \mathrm{expected}<\mathrm{rel\_error}$.
 
template<class data_t >
bool test_abs (data_t result, data_t expected, data_t abs_error, std::string description)
 Test for $|\mathrm{result}-\mathrm{expected}|/ <\mathrm{abs\_error}$.
 
template<class data_t >
bool test_fact (data_t result, data_t expected, data_t factor, std::string description)
 Test for $1/\mathrm{factor} < \mathrm{result/expected} < \mathrm{factor}$.
 
bool test_str (std::string result, std::string expected, std::string description)
 Test for $\mathrm{result}=\mathrm{expected}$.
 
bool test_gen (bool value, std::string description)
 Test for $\mathrm{result}=\mathrm{expected}$.
 
Vector testing methods
template<class vec_t , class vec2_t , class data_t >
bool test_rel_vec (int nv, const vec_t &result, const vec2_t &expected, data_t rel_error, std::string description)
 Test for $|\mathrm{result}-\mathrm{expected}|/ \mathrm{expected}<\mathrm{rel\_error}$ over each element of an array.
 
template<class vec_t , class vec2_t , class data_t >
bool test_abs_vec (int nv, const vec_t &result, const vec2_t &expected, data_t abs_error, std::string description)
 Test for $|\mathrm{result}-\mathrm{expected}|/ <\mathrm{abs\_error}$ over each element of an array.
 
template<class vec_t , class vec2_t , class data_t >
bool test_fact_vec (int nv, const vec_t &result, const vec2_t &expected, data_t factor, std::string description)
 Test for $ 1/factor < result/expected < factor $ over each element of an array.
 
template<class vec_t >
bool test_gen_vec (int nv, const vec_t &result, const vec_t &expected, std::string description)
 Test for equality of a generic array.
 
Matrix testing methods
template<class mat_t , class mat2_t , class data_t >
bool test_rel_mat (int nr, int nc, const mat_t &result, const mat2_t &expected, data_t rel_error, std::string description)
 Test for $|\mathrm{result}-\mathrm{expected}|/ \mathrm{expected}<\mathrm{rel\_error}$ over each element in a matrix.
 
template<class mat_t , class mat2_t , class data_t >
bool test_rel_nonzero_mat (int nr, int nc, const mat_t &result, const mat2_t &expected, data_t error, data_t zero_tol, std::string description)
 Test for $|\mathrm{result}-\mathrm{expected}|/ \mathrm{expected}<\mathrm{rel\_error}$ over each element in a matrix larger than a specified tolerance.
 
template<class mat_t , class mat2_t , class data_t >
bool test_abs_mat (int nr, int nc, const mat_t &result, const mat2_t &expected, data_t abs_error, std::string description)
 Test for $|\mathrm{result}-\mathrm{expected}| < \mathrm{abs\_error} $ over each element in a matrix.
 

Protected Member Functions

void process_test (bool ret, std::string d2, std::string description)
 A helper function for processing tests.
 

Protected Attributes

int ntests
 The number of tests performed.
 
int output_level
 The output level.
 
bool success
 True if all tests have passed.
 
std::string last_fail
 The description of the last failed test.
 

Friends

const test_mgr operator+ (const test_mgr &left, const test_mgr &right)
 Add two test_mgr objects (if either failed, the sum fails) More...
 

Detailed Description

Definition at line 46 of file test_mgr.h.

Member Function Documentation

◆ report()

bool o2scl::test_mgr::report ( ) const

This function reports on whether or not all tests have passed according to the current output level. It returns true if all tests have passed and false if at least one test failed.

◆ set_output_level()

void o2scl::test_mgr::set_output_level ( int  l)
inline

Possible values:

  • 0 = No output
  • 1 = Output only tests that fail
  • 2 = Output all tests

Definition at line 115 of file test_mgr.h.

◆ test_rel_nonzero_table()

template<class vec_t , class data_t >
bool o2scl::test_mgr::test_rel_nonzero_table ( const table_units< vec_t > &  result,
const table_units< vec_t > &  expected,
data_t  error,
data_t  zero_tol,
std::string  description 
)
inline

If the numbers in the expected table have an absolute value less than zero_tol, then the absolute value of the difference is used for the comparison. Otherwise, the absolute value of the relative difference is used to make the comparison.

Definition at line 479 of file test_mgr.h.

Friends And Related Function Documentation

◆ operator+

const test_mgr operator+ ( const test_mgr left,
const test_mgr right 
)
friend

The output level is set to the maximum value of left and right operand and the number of tests is set equal to the sum. The last failure descriptions of both operands are appended with a operator+() prefix, or blank if there were no failures from either.


The documentation for this class was generated from the following file:

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).