Skip to content

Commit

Permalink
Switched tests to the new tatami_test library.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Nov 26, 2024
1 parent b779da2 commit 071b543
Show file tree
Hide file tree
Showing 6 changed files with 409 additions and 64 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 @@ -26,8 +18,8 @@ add_executable(

target_link_libraries(
libtest
gtest_main
tatami_mult
tatami_test
)

target_compile_options(libtest PRIVATE -Wall -Wextra -Wpedantic -Werror)
Expand Down
64 changes: 57 additions & 7 deletions tests/src/dense_column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,27 @@ class DenseColumnTest : public ::testing::Test {
static void SetUpTestSuite() {
NR = 61;
NC = 192;
dump = tatami_test::simulate_dense_vector<double>(NR * NC, /* lower = */ -10, /* upper = */ 10, /* seed = */ 42);

dump = tatami_test::simulate_vector<double>(NR * NC, []{
tatami_test::SimulateVectorOptions opt;
opt.lower = -10;
opt.upper = 10;
opt.seed = 42;
return opt;
}());

dense.reset(new tatami::DenseRowMatrix<double, int>(NR, NC, dump));
}
};

TEST_F(DenseColumnTest, Vector) {
auto rhs = tatami_test::simulate_dense_vector<double>(NC, /* lower = */ -10, /* upper = */ 10, /* seed = */ 690);
auto rhs = tatami_test::simulate_vector<double>(NC, []{
tatami_test::SimulateVectorOptions opt;
opt.lower = -10;
opt.upper = 10;
opt.seed = 690;
return opt;
}());

// Doing a reference calculation.
std::vector<double> ref(NR);
Expand All @@ -36,7 +50,14 @@ TEST_F(DenseColumnTest, Vector) {
}

TEST_F(DenseColumnTest, Vectors) {
auto raw_rhs = tatami_test::simulate_dense_vector<double>(NC * 2, /* lower = */ -10, /* upper = */ 10, /* seed = */ 422);
auto raw_rhs = tatami_test::simulate_vector<double>(NC * 2, []{
tatami_test::SimulateVectorOptions opt;
opt.lower = -10;
opt.upper = 10;
opt.seed = 422;
return opt;
}());

std::vector<double*> rhs{ raw_rhs.data(), raw_rhs.data() + NC };

// Doing a reference calculation.
Expand All @@ -53,7 +74,14 @@ TEST_F(DenseColumnTest, Vectors) {
}

TEST_F(DenseColumnTest, TatamiDense) {
auto raw_rhs = tatami_test::simulate_dense_vector<double>(NC * 2, /* lower = */ -10, /* upper = */ 10, /* seed = */ 423);
auto raw_rhs = tatami_test::simulate_vector<double>(NC * 2, []{
tatami_test::SimulateVectorOptions opt;
opt.lower = -10;
opt.upper = 10;
opt.seed = 423;
return opt;
}());

std::vector<double*> rhs_ptrs { raw_rhs.data(), raw_rhs.data() + NC };
auto rhs_dense = std::make_shared<tatami::DenseColumnMatrix<double, int> >(NC, 2, raw_rhs);

Expand All @@ -78,7 +106,14 @@ TEST_F(DenseColumnTest, TatamiDense) {
TEST_F(DenseColumnTest, TatamiSparse) {
std::shared_ptr<tatami::Matrix<double, int> > rhs_dense, rhs_sparse;
{
auto rhs = tatami_test::simulate_sparse_vector<double>(NC * 2, 0.1, /* lower = */ -10, /* upper = */ 10, /* seed = */ 424);
auto rhs = tatami_test::simulate_vector<double>(NC * 2, []{
tatami_test::SimulateVectorOptions opt;
opt.density = 0.1;
opt.lower = -10;
opt.upper = 10;
opt.seed = 424;
return opt;
}());
rhs_dense = std::make_shared<tatami::DenseColumnMatrix<double, int> >(NC, 2, std::move(rhs));
rhs_sparse = tatami::convert_to_compressed_sparse(rhs_dense.get(), false);
}
Expand Down Expand Up @@ -120,7 +155,14 @@ TEST_F(DenseColumnTest, TatamiSparseSpecial) {

std::shared_ptr<tatami::Matrix<double, int> > rhs_dense, rhs_sparse;
{
auto rhs = tatami_test::simulate_sparse_vector<double>(NC * 6, 0.1, /* lower = */ -10, /* upper = */ 10, /* seed = */ 426);
auto rhs = tatami_test::simulate_vector<double>(NC * 6, []{
tatami_test::SimulateVectorOptions opt;
opt.density = 0.1;
opt.lower = -10;
opt.upper = 10;
opt.seed = 426;
return opt;
}());

// Remember, we're injecting Inf's to the first and/or last values of each
// row of the LHS matrix. So we need to set some of the RHS values to
Expand Down Expand Up @@ -168,7 +210,15 @@ TEST_F(DenseColumnTest, TatamiSparseNoSpecial) {

std::shared_ptr<tatami::Matrix<double, int> > rhs_sparse;
{
auto rhs = tatami_test::simulate_sparse_vector<double>(NC * 2, 0.1, /* lower = */ -10, /* upper = */ 10, /* seed = */ 421);
auto rhs = tatami_test::simulate_vector<double>(NC * 2, []{
tatami_test::SimulateVectorOptions opt;
opt.density = 0.1;
opt.lower = -10;
opt.upper = 10;
opt.seed = 421;
return opt;
}());

auto rhs_dense = std::make_shared<tatami::DenseColumnMatrix<double, int> >(NC, 2, std::move(rhs));
rhs_sparse = tatami::convert_to_compressed_sparse(rhs_dense.get(), false);
}
Expand Down
66 changes: 59 additions & 7 deletions tests/src/dense_row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,27 @@ class DenseRowTest : public ::testing::Test {
static void SetUpTestSuite() {
NR = 102;
NC = 92;
dump = tatami_test::simulate_dense_vector<double>(NR * NC, /* lower = */ -10, /* upper = */ 10, /* seed = */ 69);

dump = tatami_test::simulate_vector<double>(NR * NC, []{
tatami_test::SimulateVectorOptions opt;
opt.lower = -10;
opt.upper = 10;
opt.seed = 69;
return opt;
}());

dense.reset(new tatami::DenseRowMatrix<double, int>(NR, NC, dump));
}
};

TEST_F(DenseRowTest, Vector) {
auto rhs = tatami_test::simulate_dense_vector<double>(NC, /* lower = */ -10, /* upper = */ 10, /* seed = */ 421);
auto rhs = tatami_test::simulate_vector<double>(NC, []{
tatami_test::SimulateVectorOptions opt;
opt.lower = -10;
opt.upper = 10;
opt.seed = 421;
return opt;
}());

// Doing a reference calculation.
std::vector<double> ref(NR);
Expand All @@ -36,7 +50,14 @@ TEST_F(DenseRowTest, Vector) {
}

TEST_F(DenseRowTest, Vectors) {
auto raw_rhs = tatami_test::simulate_dense_vector<double>(NC * 2, /* lower = */ -10, /* upper = */ 10, /* seed = */ 422);
auto raw_rhs = tatami_test::simulate_vector<double>(NC * 2, []{
tatami_test::SimulateVectorOptions opt;
opt.lower = -10;
opt.upper = 10;
opt.seed = 422;
return opt;
}());

std::vector<double*> rhs{ raw_rhs.data(), raw_rhs.data() + NC };

// Doing a reference calculation.
Expand All @@ -53,7 +74,14 @@ TEST_F(DenseRowTest, Vectors) {
}

TEST_F(DenseRowTest, TatamiDense) {
auto raw_rhs = tatami_test::simulate_dense_vector<double>(NC * 2, /* lower = */ -10, /* upper = */ 10, /* seed = */ 423);
auto raw_rhs = tatami_test::simulate_vector<double>(NC * 2, []{
tatami_test::SimulateVectorOptions opt;
opt.lower = -10;
opt.upper = 10;
opt.seed = 423;
return opt;
}());

std::vector<double*> rhs_ptrs { raw_rhs.data(), raw_rhs.data() + NC };
auto rhs_dense = std::make_shared<tatami::DenseColumnMatrix<double, int> >(NC, 2, raw_rhs);

Expand All @@ -78,7 +106,15 @@ TEST_F(DenseRowTest, TatamiDense) {
TEST_F(DenseRowTest, TatamiSparse) {
std::shared_ptr<tatami::Matrix<double, int> > rhs_dense, rhs_sparse;
{
auto rhs = tatami_test::simulate_sparse_vector<double>(NC * 2, 0.1, /* lower = */ -10, /* upper = */ 10, /* seed = */ 424);
auto rhs = tatami_test::simulate_vector<double>(NC * 2, []{
tatami_test::SimulateVectorOptions opt;
opt.density = 0.1;
opt.lower = -10;
opt.upper = 10;
opt.seed = 424;
return opt;
}());

rhs_dense = std::make_shared<tatami::DenseColumnMatrix<double, int> >(NC, 2, std::move(rhs));
rhs_sparse = tatami::convert_to_compressed_sparse(rhs_dense.get(), false);
}
Expand Down Expand Up @@ -120,7 +156,15 @@ TEST_F(DenseRowTest, TatamiSparseSpecial) {

std::shared_ptr<tatami::Matrix<double, int> > rhs_dense, rhs_sparse;
{
auto rhs = tatami_test::simulate_sparse_vector<double>(NC * 6, 0.1, /* lower = */ -10, /* upper = */ 10, /* seed = */ 426);
auto rhs = tatami_test::simulate_vector<double>(NC * 6, []{
tatami_test::SimulateVectorOptions opt;
opt.density = 0.1;
opt.lower = -10;
opt.upper = 10;
opt.seed = 426;
return opt;
}());

// Remember, we're injecting Inf's to the first and/or last values of each
// row of the LHS matrix. So we need to set some of the RHS values to
// ensure that we get a good mix of NaNs and Infs in the output; otherwise
Expand Down Expand Up @@ -166,7 +210,15 @@ TEST_F(DenseRowTest, TatamiSparseNoSpecial) {

std::shared_ptr<tatami::Matrix<double, int> > rhs_sparse;
{
auto rhs = tatami_test::simulate_sparse_vector<double>(NC * 2, 0.1, /* lower = */ -10, /* upper = */ 10, /* seed = */ 421);
auto rhs = tatami_test::simulate_vector<double>(NC * 2, []{
tatami_test::SimulateVectorOptions opt;
opt.density = 0.1;
opt.lower = -10;
opt.upper = 10;
opt.seed = 421;
return opt;
}());

auto rhs_dense = std::make_shared<tatami::DenseColumnMatrix<double, int> >(NC, 2, std::move(rhs));
rhs_sparse = tatami::convert_to_compressed_sparse(rhs_dense.get(), false);
}
Expand Down
Loading

0 comments on commit 071b543

Please sign in to comment.