scran_test_utils
Test utilities for libscran projects
Loading...
Searching...
No Matches
Test utilities for libscran

Unit tests Documentation Codecov

This repository contains utilities for testing other libscran libraries. To include this in a project, just add the following chunk to the test-specific CMakeLists.txt:

include(FetchContent)
FetchContent_Declare(
scran_tests
GIT_REPOSITORY https://github.com/libscran/scran_tests
GIT_TAG master # or any version of interest
)
FetchContent_MakeAvailable(scran_tests)
target_link_libraries(mylib INTERFACE scran_tests)

This will automatically pull in GoogleTest via FetchContent so downstream projects don't have to do it themselves. Then, to use the library, we just have to add the header:

Test utilites for libscran.

We can now simulate some random data easily:

auto sparse_res = scran_tests::simulate_vector(100, []{
params.density = 0.1;
return params;
}());
auto int_res = scran_tests::simulate_vector(100, []{
params.density = 0.1;
return params;
}());
std::vector< Type_ > simulate_vector(size_t length, const SimulationParameters< Type_ > &params)
Definition simulate_vector.hpp:69
Parameters for simulate_vector().
Definition simulate_vector.hpp:22
double density
Definition simulate_vector.hpp:38

Comparison of almost-equal floating-point numbers, given a relative tolerance:

std::vector<double> v1{1.0, 2.000000001};
std::vector<double> v2{1.000000001, 2.0};
bool compare_almost_equal(double left, double right, double tol=1e-8, bool report=true)
Definition compare_almost_equal.hpp:26

Quick construction of vectors for use in EXPECT_EQ():

std::vector<double> big_array(1000);
auto subset = scran_tests::vector_n(big_array.data() + 100, 500); // slice from [100, 600)
std::vector< Type_ > vector_n(const Type_ *ptr, size_t n)
Definition vector_n.hpp:22

Expect specific error messages:

scran_tests::expect_error([&]() { throw std::runtime_error("foobar"); }, "foo");
void expect_error(Function_ fun, std::string match)
Definition expect_error.hpp:24

Test against zero-initialized assumptions:

std::vector<double> tmp(10, scran_tests::initial_value());
std::vector<double> tmp2(10, scran_tests::initial_value());
int initial_value()
Definition initial_value.hpp:24

Check out the documentation for more details.