|
scran_test_utils
Test utilities for libscran projects
|
Test utilites for libscran. More...
Classes | |
| struct | CompareAlmostEqualParameters |
Parameters for compare_almost_equal(). More... | |
| struct | SimulateCompressedSparseMatrixParameters |
Parameters for simulate_compressed_sparse_matrix(). More... | |
| struct | SimulatedCompressedSparseMatrix |
Results of simulate_compressed_sparse_matrix(). More... | |
| struct | SimulateVectorParameters |
Parameters for simulate_vector(). More... | |
Typedefs | |
| typedef std::mt19937_64 | RngEngine |
Functions | |
| bool | compare_almost_equal (double left, double right, const CompareAlmostEqualParameters ¶ms) |
| template<class LeftContainer_ , class RightContainer_ > | |
| void | compare_almost_equal_containers (const LeftContainer_ &left, const RightContainer_ &right, CompareAlmostEqualParameters params) |
| template<typename Function_ > | |
| void | expect_error (Function_ fun, std::string match) |
| int | initial_value () |
| template<typename Data_ = double, typename Index_ = int, typename Pointer_ = std::size_t> | |
| SimulatedCompressedSparseMatrix< Data_, Index_, Pointer_ > | simulate_compressed_sparse_matrix (Index_ primary, Index_ secondary, const SimulateCompressedSparseMatrixParameters< Data_ > ¶ms) |
| template<typename Type_ > | |
| constexpr Type_ | default_simulation_min () |
| template<typename Type_ = double> | |
| std::vector< Type_ > | simulate_vector (const typename std::vector< Type_ >::size_type length, const SimulateVectorParameters< Type_ > ¶ms) |
| template<typename Type_ > | |
| std::vector< Type_ > | vector_n (const Type_ *ptr, std::size_t n) |
Test utilites for libscran.
| typedef std::mt19937_64 scran_tests::RngEngine |
Type of the random number generator for simulating data.
|
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 CompareAlmostEqualParameters::relative_tolerance and their mean. If both numbers are close to zero, they are considered equal if the difference is below CompareAlmostEqualParameters::absolute_tolerance; this avoids being overly stringent for numbers that should be zero, at the cost of potentially missing large relative differences.
If both numbers are NaN, they are reported to be equal unless CompareAlmostEqualParameters::nan_equal = false. Obviously, NaNs are considered to be non-equal to any non-NaN number.
| left | One of the numbers. |
| right | The other number. |
| params | Further parameters. |
| void scran_tests::compare_almost_equal_containers | ( | const LeftContainer_ & | left, |
| const RightContainer_ & | right, | ||
| CompareAlmostEqualParameters | params ) |
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.
| LeftVector_ | Some vector-like container of floating-point values. |
| RightVector_ | Another vector-like container of floating-point values. |
| left | One of the vectors. |
| right | The other vector. |
| params | Further parameters. Note that CompareAlmostEqualParameters::report is ignored, any mismatching value will always be reported. |
|
constexpr |
| Type_ | Numeric type of the simulated value. |
Type is signed, otherwise 0. | 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.
| SimulatedCompressedSparseMatrix< Data_, Index_, Pointer_ > scran_tests::simulate_compressed_sparse_matrix | ( | Index_ | primary, |
| Index_ | secondary, | ||
| const SimulateCompressedSparseMatrixParameters< Data_ > & | params ) |
| Data_ | Numeric type of the data. |
| Index_ | Integer type of the indices. |
| Pointer_ | Integer type of the compressed sparse pointers. |
| primary | Extent of the primary dimension, i.e., along which the structural non-zero elements are compressed. For example, in a compressed sparse row matrix, the rows would be the primary dimension. |
| secondary | Extent of the secondary dimension, i.e., not the primary dimension. |
| params | Simulation parameters. |
| std::vector< Type_ > scran_tests::simulate_vector | ( | const typename std::vector< Type_ >::size_type | length, |
| const SimulateVectorParameters< 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, |
| std::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. |