Skip to content

Commit

Permalink
Updated tests to use the new tatami_test library.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Nov 30, 2024
1 parent 9355530 commit 7d955fb
Show file tree
Hide file tree
Showing 6 changed files with 399 additions and 323 deletions.
18 changes: 5 additions & 13 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/afd902e992b720d1b3e106bc5e425a5768872265.zip
tatami_test
GIT_REPOSITORY https://github.com/tatami-inc/tatami_test
GIT_TAG master
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Avoid installing GoogleTest when installing this project.
option(INSTALL_GTEST "Enable installation of googletest." OFF)

FetchContent_MakeAvailable(googletest)

enable_testing()
FetchContent_MakeAvailable(tatami_test)

add_executable(
libtest
Expand All @@ -36,7 +28,7 @@ endif()

target_compile_options(libtest PRIVATE -Wall -Wextra -Wpedantic -Werror)

target_link_libraries(libtest tatami_chunked gtest_main)
target_link_libraries(libtest tatami_chunked tatami_test)

# Making the tests discoverable.
include(GoogleTest)
Expand Down
59 changes: 30 additions & 29 deletions tests/src/CustomDenseChunkedMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ struct CustomDenseChunkedMatrixCore {
bool rowmajor = std::get<2>(params);
double cache_fraction = std::get<3>(params);

auto full = tatami_test::simulate_dense_vector<double>(matdim.first * matdim.second, -10, 10,
/* seed = */ matdim.first * matdim.second + chunkdim.first * chunkdim.second + rowmajor + 100 * cache_fraction);
auto full = tatami_test::simulate_vector<double>(matdim.first * matdim.second, [&]{
tatami_test::SimulateVectorOptions opt;
opt.lower = -10;
opt.upper = 10;
opt.seed = matdim.first * matdim.second + chunkdim.first * chunkdim.second + rowmajor + 100 * cache_fraction;
return opt;
}());
ref.reset(new tatami::DenseRowMatrix<double, int>(matdim.first, matdim.second, std::move(full)));

auto num_chunks_per_row = (matdim.second + chunkdim.second - 1) / chunkdim.second;
Expand Down Expand Up @@ -93,7 +98,7 @@ struct CustomDenseChunkedMatrixCore {
/*******************************************************/

class CustomDenseChunkedMatrixFullTest :
public ::testing::TestWithParam<std::tuple<typename CustomDenseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessParameters> >,
public ::testing::TestWithParam<std::tuple<typename CustomDenseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessOptions> >,
public CustomDenseChunkedMatrixCore {
protected:
void SetUp() {
Expand All @@ -102,10 +107,10 @@ class CustomDenseChunkedMatrixFullTest :
};

TEST_P(CustomDenseChunkedMatrixFullTest, Basic) {
auto params = tatami_test::convert_access_parameters(std::get<1>(GetParam()));
tatami_test::test_full_access(params, mock_mat.get(), ref.get());
tatami_test::test_full_access(params, simple_mat.get(), ref.get());
tatami_test::test_full_access(params, subset_mat.get(), ref.get());
auto opts = tatami_test::convert_test_access_options(std::get<1>(GetParam()));
tatami_test::test_full_access(*mock_mat, *ref, opts);
tatami_test::test_full_access(*simple_mat, *ref, opts);
tatami_test::test_full_access(*subset_mat, *ref, opts);
}

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -128,14 +133,14 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(0, 0.01, 0.1) // cache fraction
),

tatami_test::standard_test_access_parameter_combinations()
tatami_test::standard_test_access_options_combinations()
)
);

/*******************************************************/

class CustomDenseChunkedMatrixBlockTest :
public ::testing::TestWithParam<std::tuple<typename CustomDenseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessParameters, std::pair<double, double> > >,
public ::testing::TestWithParam<std::tuple<typename CustomDenseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessOptions, std::pair<double, double> > >,
public CustomDenseChunkedMatrixCore {
protected:
void SetUp() {
Expand All @@ -145,13 +150,11 @@ class CustomDenseChunkedMatrixBlockTest :

TEST_P(CustomDenseChunkedMatrixBlockTest, Basic) {
auto tparam = GetParam();
auto params = tatami_test::convert_access_parameters(std::get<1>(tparam));
auto opt = tatami_test::convert_test_access_options(std::get<1>(tparam));
auto block = std::get<2>(tparam);
auto len = params.use_row ? ref->ncol() : ref->nrow();
size_t FIRST = block.first * len, LAST = block.second * len;
tatami_test::test_block_access(params, mock_mat.get(), ref.get(), FIRST, LAST);
tatami_test::test_block_access(params, simple_mat.get(), ref.get(), FIRST, LAST);
tatami_test::test_block_access(params, subset_mat.get(), ref.get(), FIRST, LAST);
tatami_test::test_block_access(*mock_mat, *ref, block.first, block.second, opt);
tatami_test::test_block_access(*simple_mat, *ref, block.first, block.second, opt);
tatami_test::test_block_access(*subset_mat, *ref, block.first, block.second, opt);
}

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -174,20 +177,20 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(0, 0.01, 0.1) // cache fraction
),

tatami_test::standard_test_access_parameter_combinations(),
tatami_test::standard_test_access_options_combinations(),

::testing::Values( // block boundaries
std::make_pair(0.0, 0.35),
std::make_pair(0.15, 0.87),
std::make_pair(0.38, 1.0)
std::make_pair(0.15, 0.72),
std::make_pair(0.38, 0.62)
)
)
);

/*******************************************************/

class CustomDenseChunkedMatrixIndexTest :
public ::testing::TestWithParam<std::tuple<typename CustomDenseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessParameters, std::pair<double, int> > >,
public ::testing::TestWithParam<std::tuple<typename CustomDenseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessOptions, std::pair<double, double> > >,
public CustomDenseChunkedMatrixCore {
protected:
void SetUp() {
Expand All @@ -197,13 +200,11 @@ class CustomDenseChunkedMatrixIndexTest :

TEST_P(CustomDenseChunkedMatrixIndexTest, Basic) {
auto tparam = GetParam();
auto params = tatami_test::convert_access_parameters(std::get<1>(tparam));
auto opt = tatami_test::convert_test_access_options(std::get<1>(tparam));
auto index = std::get<2>(tparam);
auto len = params.use_row ? ref->ncol() : ref->nrow();
size_t FIRST = index.first * len, STEP = index.second;
tatami_test::test_indexed_access(params, mock_mat.get(), ref.get(), FIRST, STEP);
tatami_test::test_indexed_access(params, simple_mat.get(), ref.get(), FIRST, STEP);
tatami_test::test_indexed_access(params, subset_mat.get(), ref.get(), FIRST, STEP);
tatami_test::test_indexed_access(*mock_mat, *ref, index.first, index.second, opt);
tatami_test::test_indexed_access(*simple_mat, *ref, index.first, index.second, opt);
tatami_test::test_indexed_access(*subset_mat, *ref, index.first, index.second, opt);
}

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -226,12 +227,12 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(0, 0.01, 0.1) // cache fraction
),

tatami_test::standard_test_access_parameter_combinations(),
tatami_test::standard_test_access_options_combinations(),

::testing::Values( // index information.
std::make_pair(0.0, 10),
std::make_pair(0.2, 5),
std::make_pair(0.7, 3)
std::make_pair(0.0, 0.1),
std::make_pair(0.2, 0.2),
std::make_pair(0.7, 0.3)
)
)
);
69 changes: 39 additions & 30 deletions tests/src/CustomSparseChunkedMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,22 @@ class CustomSparseChunkedMatrixCore {
bool rowmajor = std::get<2>(params);
double cache_fraction = std::get<3>(params);

auto full = tatami_test::simulate_sparse_compressed<double>(matdim.second, matdim.first, 0.1, -10, 10,
/* seed = */ matdim.first * matdim.second + chunkdim.first * chunkdim.second + rowmajor + 100 * cache_fraction);
ref.reset(new tatami::CompressedSparseColumnMatrix<double, int>(matdim.first, matdim.second, std::move(full.value), std::move(full.index), std::move(full.ptr)));
auto full = tatami_test::simulate_compressed_sparse<double, int>(matdim.second, matdim.first, [&]{
tatami_test::SimulateCompressedSparseOptions opt;
opt.density = 0.1;
opt.lower = -10;
opt.upper = 10;
opt.seed = matdim.first * matdim.second + chunkdim.first * chunkdim.second + rowmajor + 100 * cache_fraction;
return opt;
}());

ref.reset(new tatami::CompressedSparseColumnMatrix<double, int>(
matdim.first,
matdim.second,
std::move(full.data),
std::move(full.index),
std::move(full.indptr)
));

auto num_chunks_per_row = (matdim.second + chunkdim.second - 1) / chunkdim.second;
auto num_chunks_per_column = (matdim.first + chunkdim.first - 1) / chunkdim.first;
Expand Down Expand Up @@ -125,7 +138,7 @@ class CustomSparseChunkedMatrixCore {
/*******************************************************/

class CustomSparseChunkedMatrixFullTest :
public ::testing::TestWithParam<std::tuple<typename CustomSparseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessParameters> >,
public ::testing::TestWithParam<std::tuple<typename CustomSparseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessOptions> >,
public CustomSparseChunkedMatrixCore {
protected:
void SetUp() {
Expand All @@ -134,10 +147,10 @@ class CustomSparseChunkedMatrixFullTest :
};

TEST_P(CustomSparseChunkedMatrixFullTest, Basic) {
auto params = tatami_test::convert_access_parameters(std::get<1>(GetParam()));
tatami_test::test_full_access(params, mock_mat.get(), ref.get());
tatami_test::test_full_access(params, simple_mat.get(), ref.get());
tatami_test::test_full_access(params, subset_mat.get(), ref.get());
auto opt = tatami_test::convert_test_access_options(std::get<1>(GetParam()));
tatami_test::test_full_access(*mock_mat, *ref, opt);
tatami_test::test_full_access(*simple_mat, *ref, opt);
tatami_test::test_full_access(*subset_mat, *ref, opt);
}

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -160,14 +173,14 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(0, 0.01, 0.1) // cache fraction
),

tatami_test::standard_test_access_parameter_combinations()
tatami_test::standard_test_access_options_combinations()
)
);

/*******************************************************/

class CustomSparseChunkedMatrixBlockTest :
public ::testing::TestWithParam<std::tuple<typename CustomSparseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessParameters, std::pair<double, double> > >,
public ::testing::TestWithParam<std::tuple<typename CustomSparseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessOptions, std::pair<double, double> > >,
public CustomSparseChunkedMatrixCore {
protected:
void SetUp() {
Expand All @@ -177,13 +190,11 @@ class CustomSparseChunkedMatrixBlockTest :

TEST_P(CustomSparseChunkedMatrixBlockTest, Basic) {
auto tparam = GetParam();
auto params = tatami_test::convert_access_parameters(std::get<1>(tparam));
auto opt = tatami_test::convert_test_access_options(std::get<1>(tparam));
auto block = std::get<2>(tparam);
auto len = params.use_row ? ref->ncol() : ref->nrow();
size_t FIRST = block.first * len, LAST = block.second * len;
tatami_test::test_block_access(params, mock_mat.get(), ref.get(), FIRST, LAST);
tatami_test::test_block_access(params, simple_mat.get(), ref.get(), FIRST, LAST);
tatami_test::test_block_access(params, subset_mat.get(), ref.get(), FIRST, LAST);
tatami_test::test_block_access(*mock_mat, *ref, block.first, block.second, opt);
tatami_test::test_block_access(*simple_mat, *ref, block.first, block.second, opt);
tatami_test::test_block_access(*subset_mat, *ref, block.first, block.second, opt);
}

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -206,20 +217,20 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(0, 0.01, 0.1) // cache fraction
),

tatami_test::standard_test_access_parameter_combinations(),
tatami_test::standard_test_access_options_combinations(),

::testing::Values( // block boundaries
std::make_pair(0.0, 0.35),
std::make_pair(0.15, 0.87),
std::make_pair(0.38, 1.0)
std::make_pair(0.15, 0.71),
std::make_pair(0.38, 0.62)
)
)
);

/*******************************************************/

class CustomSparseChunkedMatrixIndexTest :
public ::testing::TestWithParam<std::tuple<typename CustomSparseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessParameters, std::pair<double, int> > >,
public ::testing::TestWithParam<std::tuple<typename CustomSparseChunkedMatrixCore::SimulationParameters, tatami_test::StandardTestAccessOptions, std::pair<double, double> > >,
public CustomSparseChunkedMatrixCore {
protected:
void SetUp() {
Expand All @@ -229,13 +240,11 @@ class CustomSparseChunkedMatrixIndexTest :

TEST_P(CustomSparseChunkedMatrixIndexTest, Basic) {
auto tparam = GetParam();
auto params = tatami_test::convert_access_parameters(std::get<1>(tparam));
auto opt = tatami_test::convert_test_access_options(std::get<1>(tparam));
auto index = std::get<2>(tparam);
auto len = params.use_row ? ref->ncol() : ref->nrow();
size_t FIRST = index.first * len, STEP = index.second;
tatami_test::test_indexed_access(params, mock_mat.get(), ref.get(), FIRST, STEP);
tatami_test::test_indexed_access(params, simple_mat.get(), ref.get(), FIRST, STEP);
tatami_test::test_indexed_access(params, subset_mat.get(), ref.get(), FIRST, STEP);
tatami_test::test_indexed_access(*mock_mat, *ref, index.first, index.second, opt);
tatami_test::test_indexed_access(*simple_mat, *ref, index.first, index.second, opt);
tatami_test::test_indexed_access(*subset_mat, *ref, index.first, index.second, opt);
}

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -258,12 +267,12 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(0, 0.01, 0.1) // cache fraction
),

tatami_test::standard_test_access_parameter_combinations(),
tatami_test::standard_test_access_options_combinations(),

::testing::Values( // index information.
std::make_pair(0.0, 10),
std::make_pair(0.2, 5),
std::make_pair(0.7, 3)
std::make_pair(0.0, 0.15),
std::make_pair(0.2, 0.24),
std::make_pair(0.7, 0.3)
)
)
);
Loading

0 comments on commit 7d955fb

Please sign in to comment.