scran_test_utils
Test utilities for libscran projects
|
Test utilites for libscran. More...
Classes | |
struct | SimulationParameters |
Parameters for simulate_vector() . More... | |
Functions | |
bool | compare_almost_equal (double left, double right, double tol=1e-8, bool report=true) |
template<class Vector_ > | |
void | compare_almost_equal (const Vector_ &left, const Vector_ &right, double tol=1e-8) |
template<typename Function_ > | |
void | expect_error (Function_ fun, std::string match) |
int | initial_value () |
template<typename Type_ = double> | |
std::vector< Type_ > | simulate_vector (size_t length, const SimulationParameters< Type_ > ¶ms) |
template<typename Type_ > | |
std::vector< Type_ > | vector_n (const Type_ *ptr, size_t n) |
Test utilites for libscran.
void scran_tests::compare_almost_equal | ( | const Vector_ & | left, |
const Vector_ & | right, | ||
double | tol = 1e-8 |
||
) |
Check if two vectors contain an equal number of almost-equal floats. This compares the corresponding elements from each vector using compare_almost_equal()
. Any test failure is reported via GoogleTest.
Vector_ | Some vector-like container of floating-point values. |
left | One of the vectors. |
right | The other vector. |
tol | The tolerance for the comparison, passed to the other compare_almost_equal() function. |
|
inline |
Check if two floating-point numbers are equal, accounting for some relative difference. Two numbers are considered equal if their difference is less than the product of tolerance
and their mean. If both numbers are close to zero, they are considered equal if the difference is below 1e-15; this avoids being overly stringent for numbers that should be zero, at the cost of potentially missing large relative differences.
left | One of the numbers. |
right | The other number. |
tol | The tolerance for the comparison. |
report | Whether to report the error via GoogleTest. |
void scran_tests::expect_error | ( | Function_ | fun, |
std::string | match | ||
) |
Expect an error to be raised with the given message. If no error is raised, or if the error message does not match match
, an error is reported via GoogleTest.
Function_ | Function to call with no arguments. |
fun | Function that should raise an error. |
match | String to be matched against the error message. |
|
inline |
Some functions store their output in a user-supplied pointer to a pre-allocated array. Such functions should not assume that the array has been zeroed. Incorrectly making this assumption can lead to subtle bugs when the functions are called with non-zeroed buffers. To test that this assumption is not present in function X()
, we can initialize an output
buffer with a non-zero initial value from the initial_value()
function below. After calling X()
with output
, we can compare the contents of output
against the expected output to verify that the function ignores the non-zero initial value. If the expected output is not readily available, we could instead initialize a separate vector with another call to initial_value()
and call X()
on it. Any inconsistency in the results would indicate that the variable initial_value()
is affecting the results.
std::vector< Type_ > scran_tests::simulate_vector | ( | size_t | length, |
const SimulationParameters< Type_ > & | params | ||
) |
Simulate a vector of random values. If SimulationParameters::density < 1
, this will be a sparse vector with structural zeros.
Type_ | Numeric type of the simulated value. |
length | Length of the vector. |
params | Simulation parameters. |
std::vector< Type_ > scran_tests::vector_n | ( | const Type_ * | ptr, |
size_t | n | ||
) |
Quickly create a vector from an array, primarily for convenient use in EXPECT_EQ
with another vector.
[in] | ptr | Pointer to the start of an array. |
n | Length of the array. |