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:
#include "scran_tests/scran_tests.hpp"We can now simulate some random data easily:
auto res = scran_tests::simulate_vector(
100,
scran_tests::SimulateVectorParameters()
);
auto sparse_res = scran_tests::simulate_vector(100, []{
scran_tests::SimulateVectorParameters params
params.density = 0.1;
return params;
}());
auto int_res = scran_tests::simulate_vector(100, []{
scran_tests::SimulateVectorParameters<uint16_t> params
params.density = 0.1;
return params;
}());
auto compressed_sparse = scran_tests::simulate_compressed_sparse_matrix(
100,
200,
scran_tests::SimulateCompressedSparseMatrixParameters<double>{}
}());Comparison of almost-equal floating-point numbers, given a relative tolerance:
scran_tests::compare_almost_equal(1.0, 1.0000000001, {});
std::vector<double> v1{1.0, 2.000000001};
std::vector<double> v2{1.000000001, 2.0};
scran_tests::compare_almost_equal_containers(v1, v2, {});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)Expect specific error messages:
scran_tests::expect_error([&]() { throw std::runtime_error("foobar"); }, "foo");Test against zero-initialized assumptions:
std::vector<double> tmp(10, scran_tests::initial_value());
std::vector<double> tmp2(10, scran_tests::initial_value());Check out the documentation for more details.