tatami_test
Utilities for testing tatami libraries
Loading...
Searching...
No Matches
tatami_test Namespace Reference

Utilities for testing tatami libraries. More...

Classes

class  ForcedOracleWrapper
 Force oracular extraction. More...
 
class  ReversedIndicesWrapper
 Reverse indices for sparse extraction. More...
 
struct  SimulateCompressedSparseOptions
 Options for simulate_compressed_sparse(). More...
 
struct  SimulateCompressedSparseResult
 Result of simulate_compressed_sparse(). More...
 
struct  SimulateVectorOptions
 Options for simulate_vector(). More...
 
struct  SparseVector
 Sparse vector. More...
 
struct  TestAccessOptions
 Options for test_full_access() and friends. More...
 

Typedefs

typedef std::tuple< bool, bool, TestAccessOrder, int > StandardTestAccessOptions
 
typedef std::mt19937_64 RngEngine
 
typedef RngEngine::result_type SeedType
 

Enumerations

enum class  TestAccessOrder : char { FORWARD , REVERSE , RANDOM }
 

Functions

template<typename Index_ >
tatami::VectorPtr< Index_ > create_indexed_subset (const Index_ extent, const double relative_start, const double probability, const SeedType seed)
 
template<typename Value_ , typename Index_ >
std::vector< Value_ > fetch (tatami::MyopicDenseExtractor< Value_, Index_ > &ext, Index_ i, std::size_t number)
 
template<typename Value_ , typename Index_ >
std::vector< Value_ > fetch (tatami::OracularDenseExtractor< Value_, Index_ > &ext, std::size_t number)
 
template<typename Value_ , typename Index_ >
SparseVector< Value_, Index_ > fetch (tatami::MyopicSparseExtractor< Value_, Index_ > &ext, Index_ i, std::size_t number)
 
template<typename Value_ , typename Index_ >
SparseVector< Value_, Index_ > fetch (tatami::OracularSparseExtractor< Value_, Index_ > &ext, std::size_t number)
 
template<typename Value_ , typename Index_ >
SimulateCompressedSparseResult< Value_, Index_ > simulate_compressed_sparse (const Index_ primary, const Index_ secondary, const SimulateCompressedSparseOptions &options)
 
template<typename Type_ , typename Length_ >
std::vector< Type_ > simulate_vector (const Length_ length, const SimulateVectorOptions &options)
 
template<typename Type_ , typename Index_ >
std::vector< Type_ > simulate_vector (const Index_ nrow, const Index_ ncol, const SimulateVectorOptions &options)
 
TestAccessOptions convert_test_access_options (const StandardTestAccessOptions &x)
 
auto standard_test_access_options_combinations ()
 
template<typename Value_ , typename Index_ >
void test_full_access (const tatami::Matrix< Value_, Index_ > &matrix, const tatami::Matrix< Value_, Index_ > &reference, const TestAccessOptions &options)
 
template<typename Value_ , typename Index_ >
void test_block_access (const tatami::Matrix< Value_, Index_ > &matrix, const tatami::Matrix< Value_, Index_ > &reference, double relative_start, double relative_length, const TestAccessOptions &options)
 
template<typename Value_ , typename Index_ >
void test_indexed_access (const tatami::Matrix< Value_, Index_ > &matrix, const tatami::Matrix< Value_, Index_ > &reference, double relative_start, double probability, const TestAccessOptions &options)
 
template<typename Value_ , typename Index_ >
void test_simple_column_access (const tatami::Matrix< Value_, Index_ > &matrix, const tatami::Matrix< Value_, Index_ > &reference)
 
template<typename Value_ , typename Index_ >
void test_simple_row_access (const tatami::Matrix< Value_, Index_ > &matrix, const tatami::Matrix< Value_, Index_ > &reference)
 
template<typename Value_ , typename Index_ >
void test_unsorted_full_access (const tatami::Matrix< Value_, Index_ > &matrix, const TestAccessOptions &options)
 
template<typename Value_ , typename Index_ >
void test_unsorted_block_access (const tatami::Matrix< Value_, Index_ > &matrix, double relative_start, double relative_length, const TestAccessOptions &options)
 
template<typename Value_ , typename Index_ >
void test_unsorted_indexed_access (const tatami::Matrix< Value_, Index_ > &matrix, double relative_start, double probability, const TestAccessOptions &options)
 
template<class Function_ >
void throws_error (Function_ fun, const std::string &msg)
 

Detailed Description

Utilities for testing tatami libraries.

Typedef Documentation

◆ RngEngine

typedef std::mt19937_64 tatami_test::RngEngine

Type of the pseudo-random number generator.

◆ SeedType

typedef RngEngine::result_type tatami_test::SeedType

Type of the seed for RngEngine.

◆ StandardTestAccessOptions

typedef std::tuple<bool, bool, TestAccessOrder, int> tatami_test::StandardTestAccessOptions

Contents of TestAccessOptions as a tuple. This is required for GoogleTest's parametrized generators, see standard_test_access_options_combinations().

Enumeration Type Documentation

◆ TestAccessOrder

enum class tatami_test::TestAccessOrder : char
strong

Order for accessing rows/columns during tatami::Matrix access tests.

  • FORWARD: rows/columns are accessed in strictly increasing order.
  • REVERSE: rows/columns are accessed in strictly decreasing order.
  • RANDOM: rows/columns are accessed in random order.

Function Documentation

◆ convert_test_access_options()

TestAccessOptions tatami_test::convert_test_access_options ( const StandardTestAccessOptions & x)
inline

Convert from tuple-like options into a TestAccessOptions object. This allows TEST_P bodies to easily convert the GetParam()-supplied tuple into options for test_full_access() and friends.

Parameters
xOptions as a tuple.
Returns
The same options as a TestAccessOptions object.

◆ create_indexed_subset()

template<typename Index_ >
tatami::VectorPtr< Index_ > tatami_test::create_indexed_subset ( const Index_ extent,
const double relative_start,
const double probability,
const SeedType seed )

Create a random subset of sorted and unique indices, typically corresponding to elements of the non-target dimension.

Template Parameters
Index_Integer type for the dimension elements.
Parameters
extentExtent of the non-target dimension.
relative_startStart of the indexed subset, as a proportion of the extent of the non-target dimension. The (floored) product of this value and extent is used as the index of the first element in the indexed subset. This should lie in [0, 1).
probabilityProbability of sampling elements into the indexed subset. This should lie in [0, 1]. Only elements after the first index (as defined by relative_start) are considered.
seedSeed for the PRNG.
Returns
Pointer to a vector of indices of sampled elements. The vector will be empty if extent = 0, otherwise it is guaranteed to contain at least one element corresponding to relative_start.

◆ fetch() [1/4]

template<typename Value_ , typename Index_ >
std::vector< Value_ > tatami_test::fetch ( tatami::MyopicDenseExtractor< Value_, Index_ > & ext,
Index_ i,
std::size_t number )
Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
extAn extractor object.
iRow/column index to extract.
numberNumber of elements to extract along the non-target dimension.
Returns
Vector of length number, containing the extracted values from row/column i.

◆ fetch() [2/4]

template<typename Value_ , typename Index_ >
SparseVector< Value_, Index_ > tatami_test::fetch ( tatami::MyopicSparseExtractor< Value_, Index_ > & ext,
Index_ i,
std::size_t number )
Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
extAn extractor object.
iRow/column index to extract.
numberNumber of elements to extract along the non-target dimension.
Returns
Sparse vector containing up to number extracted values from row/column i.

◆ fetch() [3/4]

template<typename Value_ , typename Index_ >
std::vector< Value_ > tatami_test::fetch ( tatami::OracularDenseExtractor< Value_, Index_ > & ext,
std::size_t number )
Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
extAn extractor object.
numberNumber of elements to extract along the non-target dimension.
Returns
Vector of length number, containing the extracted values from the next row/column.

◆ fetch() [4/4]

template<typename Value_ , typename Index_ >
SparseVector< Value_, Index_ > tatami_test::fetch ( tatami::OracularSparseExtractor< Value_, Index_ > & ext,
std::size_t number )
Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
extAn extractor object.
numberNumber of elements to extract along the non-target dimension.
Returns
Sparse vector containing up to number extracted values from the next row/column.

◆ simulate_compressed_sparse()

template<typename Value_ , typename Index_ >
SimulateCompressedSparseResult< Value_, Index_ > tatami_test::simulate_compressed_sparse ( const Index_ primary,
const Index_ secondary,
const SimulateCompressedSparseOptions & options )

Simulate values in a compressed sparse matrix.

Template Parameters
Value_Type of simulated value.
Index_Integer type for the index.
Parameters
primaryExtent of the primary dimension, i.e., the dimension used to compress non-zero elements.
secondaryExtent of the secondary dimension.
optionsSimulation options.
Returns
Simulated values that can be used to construct a compressed sparse matrix.

◆ simulate_vector() [1/2]

template<typename Type_ , typename Index_ >
std::vector< Type_ > tatami_test::simulate_vector ( const Index_ nrow,
const Index_ ncol,
const SimulateVectorOptions & options )

Overload of simulate_vector() for simulating the contents of a dense random matrix.

Template Parameters
Type_Type of value to be simulated.
Index_Integer type of the dimension extents.
Parameters
nrowNumber of rows in the matrix.
ncolNumber of columns in the matrix.
optionsSimulation options.
Returns
Vector of simulated values of length equal to the product of nrow and ncol.

◆ simulate_vector() [2/2]

template<typename Type_ , typename Length_ >
std::vector< Type_ > tatami_test::simulate_vector ( const Length_ length,
const SimulateVectorOptions & options )

Simulate a vector of values from a uniform distribution.

Template Parameters
Type_Type of value to be simulated.
Length_Integer type of the length of the output vector.
Parameters
lengthLength of the array of values to simulate.
optionsSimulation options.
Returns
Vector of simulated values.

◆ standard_test_access_options_combinations()

auto tatami_test::standard_test_access_options_combinations ( )
inline
Returns
A parametrized GoogleTest generator for all TestAccessOptions combinations. This should be used inside a INSTANTIATE_TEST_SUITE_P macro, which ensures that GetParam() in the TEST_P body returns a StandardTestAccessOptions instance.

◆ test_block_access()

template<typename Value_ , typename Index_ >
void tatami_test::test_block_access ( const tatami::Matrix< Value_, Index_ > & matrix,
const tatami::Matrix< Value_, Index_ > & reference,
double relative_start,
double relative_length,
const TestAccessOptions & options )

Test access to a contiguous block of a row/column. Any discrepancies between matrix and reference will raise a GoogleTest error.

Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
matrixMatrix for which to test access.
referenceReference matrix containing the same values as matrix. This typically uses a "known-good" representation like a tatami::DenseRowMatrix.
relative_startStart of the block, as a proportion of the extent of the non-target dimension. The (floored) product of this value and the non-target extent is used as the index of the first row/column of the block. This should lie in [0, 1).
relative_lengthLength of the block, as a proportion of the extent of the non-target dimension. This should lie in [0, 1), and the sum of relative_start and relative_length should be no greater than 1. The (floored) product of this value and the non-target extent is used as the number of rows/columns in the block.
optionsFurther options for testing.

◆ test_full_access()

template<typename Value_ , typename Index_ >
void tatami_test::test_full_access ( const tatami::Matrix< Value_, Index_ > & matrix,
const tatami::Matrix< Value_, Index_ > & reference,
const TestAccessOptions & options )

Test access to the full extent of a row/column. Any discrepancies between matrix and reference will raise a GoogleTest error.

Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
matrixMatrix for which to test access.
referenceReference matrix containing the same values as matrix. This typically uses a "known-good" representation like a tatami::DenseRowMatrix.
optionsFurther options for testing.

◆ test_indexed_access()

template<typename Value_ , typename Index_ >
void tatami_test::test_indexed_access ( const tatami::Matrix< Value_, Index_ > & matrix,
const tatami::Matrix< Value_, Index_ > & reference,
double relative_start,
double probability,
const TestAccessOptions & options )

Test access to an indexed subset of a row/column. Any discrepancies between matrix and reference will raise a GoogleTest error.

Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
matrixMatrix for which to test access.
referenceReference matrix containing the same values as matrix. This typically uses a "known-good" representation like a tatami::DenseRowMatrix.
relative_startStart of the indexed subset, as a proportion of the extent of the non-target dimension. The (floored) product of this value and the non-target extent is used as the index of the first row/column in the indexed subset. This should lie in [0, 1).
probabilityProbability of sampling rows/columns when simulating the indexed subset. This should lie in [0, 1]. Only rows/columns after the first index (as defined by relative_start) are considered.
optionsFurther options for testing.

◆ test_simple_column_access()

template<typename Value_ , typename Index_ >
void tatami_test::test_simple_column_access ( const tatami::Matrix< Value_, Index_ > & matrix,
const tatami::Matrix< Value_, Index_ > & reference )

Equivalent to test_full_access() with TestAccessOptions::use_row = false. All other options are set to their defaults. This is intended for quick testing of matrix access when a full parametrized test suite is not required.

Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
matrixMatrix for which to test access.
referenceReference matrix containing the same values as matrix. This typically uses a "known-good" representation like a tatami::DenseRowMatrix.

◆ test_simple_row_access()

template<typename Value_ , typename Index_ >
void tatami_test::test_simple_row_access ( const tatami::Matrix< Value_, Index_ > & matrix,
const tatami::Matrix< Value_, Index_ > & reference )

Equivalent to test_full_access() with TestAccessOptions::use_row = true. All other options are set to their defaults. This is intended for quick testing of matrix access when a full parametrized test suite is not required.

Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
matrixMatrix for which to test access.
referenceReference matrix containing the same values as matrix. This typically uses a "known-good" representation like a tatami::DenseRowMatrix.

◆ test_unsorted_block_access()

template<typename Value_ , typename Index_ >
void tatami_test::test_unsorted_block_access ( const tatami::Matrix< Value_, Index_ > & matrix,
double relative_start,
double relative_length,
const TestAccessOptions & options )

Test unsorted sparse access to a contiguous block of a row/column. Any discrepancies between sorted and unsorted accesses on matrix will raise a GoogleTest error. This is intended for tatami::Matrix subclasses where tatami::Options::sparse_ordered_index = false has an effect. Subclasses implementing delayed operations should consider tests with UnorderedWrapper instances to check that unordered access in the seed is handled correctly.

Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
matrixMatrix for which to test access.
relative_startStart of the block, as a proportion of the extent of the non-target dimension. The (floored) product of this value and the non-target extent is used as the index of the first row/column of the block. This should lie in [0, 1).
relative_lengthLength of the block, as a proportion of the extent of the non-target dimension. This should lie in [0, 1), and the sum of relative_start and relative_length should be no greater than 1. The (floored) product of this value and the non-target extent is used as the number of rows/columns in the block.
optionsFurther options for testing.

◆ test_unsorted_full_access()

template<typename Value_ , typename Index_ >
void tatami_test::test_unsorted_full_access ( const tatami::Matrix< Value_, Index_ > & matrix,
const TestAccessOptions & options )

Test unsorted sparse access to the full extent of a row/column. Any discrepancies between sorted and unsorted accesses on matrix will raise a GoogleTest error. This is intended for tatami::Matrix subclasses where tatami::Options::sparse_ordered_index = false has an effect. Subclasses implementing delayed operations should consider tests with UnorderedWrapper instances to check that unordered access in the seed is handled correctly.

Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
matrixMatrix for which to test access.
optionsFurther options for testing.

◆ test_unsorted_indexed_access()

template<typename Value_ , typename Index_ >
void tatami_test::test_unsorted_indexed_access ( const tatami::Matrix< Value_, Index_ > & matrix,
double relative_start,
double probability,
const TestAccessOptions & options )

Test unsorted sparse access to an indexed subset of a row/column. Any discrepancies between sorted and unsorted accesses on matrix will raise a GoogleTest error. This function is intended for tatami::Matrix subclasses where tatami::Options::sparse_ordered_index = false has an effect. Subclasses implementing delayed operations should consider tests with UnorderedWrapper instances to check that unordered access in the seed is handled correctly.

Template Parameters
Value_Type of the data.
Index_Integer type for the row/column index.
Parameters
matrixMatrix for which to test access.
relative_startStart of the indexed subset, as a proportion of the extent of the non-target dimension. The (floored) product of this value and the non-target extent is used as the index of the first row/column in the indexed subset. This should lie in [0, 1).
probabilityProbability of sampling rows/columns when simulating the indexed subset. This should lie in [0, 1]. Only rows/columns after the first index (as defined by relative_start) are considered.
optionsFurther options for testing.

◆ throws_error()

template<class Function_ >
void tatami_test::throws_error ( Function_ fun,
const std::string & msg )

Checks that an exception is thrown with the expected message.

Template Parameters
Function_A function that takes no arguments.
Parameters
funA function that may or may not throw an exception.
msgAny part of the expected error message.