Class test_mgr (o2scl)¶
-
class
o2scl
::
test_mgr
¶ A class to manage testing and record success and failure.
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.
Possible values:
0 = No output
1 = Output only tests that fail
2 = Output all tests
-
int
get_ntests
() const¶ Return the number of tests performed so far.
Main testing methods
-
template<class
data_t
= double>
booltest_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
= double>
booltest_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
= double>
booltest_abs_boost
(data_t result, data_t expected, data_t abs_error, std::string description)¶ Testing functions for
boost::multiprecision
numbers.This function is similar to test_abs(), but replaces
isnan
and related functions with boost versions fromboost::multiprecision::number
.
-
template<class
data_t
= double>
booltest_rel_boost
(data_t result, data_t expected, data_t rel_error, std::string description)¶ Testing functions for
boost::multiprecision
numbers.This function is similar to test_abs(), but replaces
isnan
and related functions with boost versions fromboost::multiprecision::number
.
-
template<class
data_t
>
booltest_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
, classvec2_t
, classdata_t
>
booltest_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
, classvec2_t
, classdata_t
>
booltest_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.
Matrix testing methods
-
template<class
mat_t
, classmat2_t
, classdata_t
>
booltest_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
, classmat2_t
, classdata_t
>
booltest_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
, classmat2_t
, classdata_t
>
booltest_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.
-
template<class
vec_t
, classdata_t
>
booltest_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 tableresult
.If the numbers in the
expected
table have an absolute value less thanzero_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.
-
friend const test_mgr
operator+
(const test_mgr &left, const test_mgr &right)¶ Add two test_mgr objects (if either failed, the sum fails)
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.
Public 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.
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.
Protected Functions
-
void
process_test
(bool ret, std::string d2, std::string description)¶ A helper function for processing tests.
-
bool