From 008f6814376a6b81e2eb632a7ee7e7f35f421a6d Mon Sep 17 00:00:00 2001 From: LTLA Date: Sun, 31 Mar 2024 14:29:37 -0700 Subject: [PATCH] Updated tests to use the latest tatami. Also turned on all warnings and fixed the associated errors. --- include/tatami_mtx/load_matrix.hpp | 13 +- tests/CMakeLists.txt | 2 + tests/src/load_matrix.cpp | 212 +++++++---------------------- 3 files changed, 59 insertions(+), 168 deletions(-) diff --git a/include/tatami_mtx/load_matrix.hpp b/include/tatami_mtx/load_matrix.hpp index 48333ee..6c0a494 100644 --- a/include/tatami_mtx/load_matrix.hpp +++ b/include/tatami_mtx/load_matrix.hpp @@ -216,7 +216,7 @@ std::shared_ptr > load_matrix(byteme::Reader& read * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. */ template -std::shared_ptr > load_matrix_from_text_file(const char * filepath, int compression = 0, size_t bufsize = 65536) { +std::shared_ptr > load_matrix_from_text_file(const char * filepath, size_t bufsize = 65536) { byteme::RawFileReader reader(filepath, bufsize); return load_matrix(reader); } @@ -279,12 +279,11 @@ std::shared_ptr > load_matrix_from_some_file(const * * @param buffer Array containing the contents of an uncompressed Matrix Market file. * @param n Length of the array. - * @param bufsize Size of the buffer (in bytes) to use when decompressing the file contents. * * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. */ template -std::shared_ptr > load_matrix_from_text_buffer(const unsigned char * buffer, size_t n, size_t bufsize = 65536) { +std::shared_ptr > load_matrix_from_text_buffer(const unsigned char * buffer, size_t n) { byteme::RawBufferReader reader(buffer, n); return load_matrix(reader); } @@ -303,13 +302,15 @@ std::shared_ptr > load_matrix_from_text_buffer(con * * @param buffer Array containing the contents of a Matrix Market file after Gzip/Zlib compression. * @param n Length of the array. + * @param compression Compression of the stream - DEFLATE (0), Zlib (1) or Gzip (2). + * Default of 3 will auto-detect between Zlib and Gzip based on the headers. * @param bufsize Size of the buffer (in bytes) to use when decompressing the file contents. * * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. */ template -std::shared_ptr > load_matrix_from_zlib_buffer(const unsigned char * buffer, size_t n, int compression = 0, size_t bufsize = 65536) { - byteme::ZlibBufferReader reader(buffer, n, 3, bufsize); +std::shared_ptr > load_matrix_from_zlib_buffer(const unsigned char * buffer, size_t n, int compression = 3, size_t bufsize = 65536) { + byteme::ZlibBufferReader reader(buffer, n, compression, bufsize); return load_matrix(reader); } @@ -331,7 +332,7 @@ std::shared_ptr > load_matrix_from_zlib_buffer(con */ template std::shared_ptr > load_matrix_from_some_buffer(const unsigned char * buffer, size_t n, size_t bufsize = 65536) { - byteme::SomeBufferReader reader(buffer, n); + byteme::SomeBufferReader reader(buffer, n, bufsize); return load_matrix(reader); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b5c1a27..249d50c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,6 +24,8 @@ if (NOT HAVE_CXX_FS) target_link_libraries(libtest stdc++fs) endif() +target_compile_options(libtest PRIVATE -Wall -Wextra -Wpedantic -Werror) + set(CODE_COVERAGE OFF CACHE BOOL "Enable coverage testing") if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") target_compile_options(libtest PRIVATE -O0 -g --coverage) diff --git a/tests/src/load_matrix.cpp b/tests/src/load_matrix.cpp index 61b751d..c725b4a 100644 --- a/tests/src/load_matrix.cpp +++ b/tests/src/load_matrix.cpp @@ -3,6 +3,8 @@ #include "byteme/byteme.hpp" #include "byteme/temp_file_path.hpp" #include "eminem/eminem.hpp" +#include "tatami_test/tatami_test.hpp" + #include "tatami_mtx/tatami_mtx.hpp" #include @@ -87,8 +89,9 @@ class LoadMatrixTestMethods { stream.write(std::to_string(NC)); auto ext = ref->dense_column(); + std::vector buffer(NR); for (size_t c = 0; c < NC; ++c) { - auto col = ext->fetch(c); + auto col = ext->fetch(c, buffer.data()); for (size_t r = 0; r < NR; ++r) { stream.write('\n'); stream.write(std::to_string(static_cast(col[r]))); @@ -119,13 +122,8 @@ TEST_F(LoadMatrixInputTest, SimpleBuffer) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } // Automatic. @@ -133,13 +131,8 @@ TEST_F(LoadMatrixInputTest, SimpleBuffer) { auto out = tatami_mtx::load_matrix_from_some_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } } @@ -155,13 +148,8 @@ TEST_F(LoadMatrixInputTest, SimpleText) { auto out = tatami_mtx::load_matrix_from_text_file(path.c_str()); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } // Automatic. @@ -169,13 +157,8 @@ TEST_F(LoadMatrixInputTest, SimpleText) { auto out = tatami_mtx::load_matrix_from_some_file(path.c_str()); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } } @@ -191,13 +174,8 @@ TEST_F(LoadMatrixInputTest, ZlibBuffer) { auto out = tatami_mtx::load_matrix_from_zlib_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } // Automatic. @@ -205,13 +183,8 @@ TEST_F(LoadMatrixInputTest, ZlibBuffer) { auto out = tatami_mtx::load_matrix_from_some_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } } @@ -227,13 +200,8 @@ TEST_F(LoadMatrixInputTest, GzipFile) { auto out = tatami_mtx::load_matrix_from_gzip_file(path.c_str()); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } // Automatic. @@ -241,13 +209,8 @@ TEST_F(LoadMatrixInputTest, GzipFile) { auto out = tatami_mtx::load_matrix_from_some_file(path.c_str()); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } } @@ -267,13 +230,8 @@ TEST_F(LoadMatrixIndexTest, Index8) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixIndexTest, Index16) { @@ -286,13 +244,8 @@ TEST_F(LoadMatrixIndexTest, Index16) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixIndexTest, Index32) { @@ -305,13 +258,8 @@ TEST_F(LoadMatrixIndexTest, Index32) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixIndexTest, IndexCustom) { @@ -324,13 +272,8 @@ TEST_F(LoadMatrixIndexTest, IndexCustom) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } /********************************************* @@ -347,13 +290,8 @@ TEST_F(LoadMatrixIndexTest, TempIndex8) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixIndexTest, TempIndex16) { @@ -366,13 +304,8 @@ TEST_F(LoadMatrixIndexTest, TempIndex16) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixIndexTest, TempIndex32) { @@ -385,13 +318,8 @@ TEST_F(LoadMatrixIndexTest, TempIndex32) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } /****************************************** @@ -410,13 +338,8 @@ TEST_F(LoadMatrixIntegerTypeTest, CoordinateAutomatic) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixIntegerTypeTest, CoordinateCustom) { @@ -429,13 +352,8 @@ TEST_F(LoadMatrixIntegerTypeTest, CoordinateCustom) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixIntegerTypeTest, ArrayAutomatic) { @@ -448,13 +366,8 @@ TEST_F(LoadMatrixIntegerTypeTest, ArrayAutomatic) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_TRUE(out->prefer_rows()); EXPECT_FALSE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixIntegerTypeTest, ArrayCustom) { @@ -467,13 +380,8 @@ TEST_F(LoadMatrixIntegerTypeTest, ArrayCustom) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_FALSE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } /**************************************** @@ -492,13 +400,8 @@ TEST_F(LoadMatrixFloatTypeTest, CoordinateAutomatic) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixFloatTypeTest, CoordinateCustom) { @@ -511,13 +414,8 @@ TEST_F(LoadMatrixFloatTypeTest, CoordinateCustom) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixFloatTypeTest, ArrayAutomatic) { @@ -530,13 +428,8 @@ TEST_F(LoadMatrixFloatTypeTest, ArrayAutomatic) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_TRUE(out->prefer_rows()); EXPECT_FALSE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); } TEST_F(LoadMatrixFloatTypeTest, ArrayCustom) { @@ -549,11 +442,6 @@ TEST_F(LoadMatrixFloatTypeTest, ArrayCustom) { auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); EXPECT_FALSE(out->prefer_rows()); EXPECT_FALSE(out->sparse()); - - auto owrk = out->dense_column(); - auto rwrk = ref->dense_column(); - for (size_t i = 0; i < NC; ++i) { - auto stuff = owrk->fetch(i); - EXPECT_EQ(stuff, rwrk->fetch(i)); - } + tatami_test::test_simple_row_access(out.get(), ref.get()); + tatami_test::test_simple_column_access(out.get(), ref.get()); }