From 77b73fd56b180ba300652f796d19154580ad7e6c Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Fri, 23 Oct 2026 23:03:29 +0200 Subject: [PATCH 1/7] Reject k-mer matches before their indexed string --- .github/workflows/build.yml | 9 ++- CMakeLists.txt | 6 ++ include/spectrum_preserving_string_set.hpp | 2 +- test/test_encoded_boundaries.cpp | 71 ++++++++++++++++++++++ 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 test/test_encoded_boundaries.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59b261d..4799869 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,6 +8,7 @@ jobs: build: strategy: matrix: + build_type: [Release] compiler: - { name: gcc, version: 11} - { name: gcc, version: 12} @@ -16,7 +17,10 @@ jobs: - { name: clang, version: 16} - { name: clang, version: 17} - { name: clang, version: 18} - name: Build (${{ matrix.compiler.name }} ${{ matrix.compiler.version }}) + include: + - compiler: { name: gcc, version: 14} + build_type: Debug + name: Build (${{ matrix.compiler.name }} ${{ matrix.compiler.version }})${{ matrix.build_type == 'Debug' && ' with assertions' || '' }} runs-on: ubuntu-latest steps: - name: Install dependencies @@ -41,5 +45,6 @@ jobs: submodules: recursive - name: Build run: | - cmake -B ./build + cmake -B ./build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build ./build --parallel + ctest --test-dir ./build --output-on-failure diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e20dbf..31744a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,8 @@ target_link_libraries(sshash_static PUBLIC ZLIB::ZLIB) add_library(sshash::sshash ALIAS sshash_static) if (SSHASH_BUILD_EXECUTABLES) + enable_testing() + add_executable(sshash tools/sshash.cpp) target_link_libraries(sshash PRIVATE sshash_static) @@ -102,6 +104,10 @@ if (SSHASH_BUILD_EXECUTABLES) add_executable(check test/check.cpp) target_link_libraries(check PRIVATE sshash_static) + add_executable(test_encoded_boundaries test/test_encoded_boundaries.cpp) + target_link_libraries(test_encoded_boundaries PRIVATE sshash_static) + add_test(NAME encoded_boundaries COMMAND test_encoded_boundaries) + if (CONDA_BUILD) install(TARGETS sshash RUNTIME DESTINATION bin) endif () diff --git a/include/spectrum_preserving_string_set.hpp b/include/spectrum_preserving_string_set.hpp index b5fd5eb..0d885a2 100644 --- a/include/spectrum_preserving_string_set.hpp +++ b/include/spectrum_preserving_string_set.hpp @@ -261,7 +261,7 @@ struct spectrum_preserving_string_set // strings_offsets.offset_to_id(res, p, k); } - if (res.kmer_offset < res.string_end - k + 1) return true; + if (res.kmer_offset >= res.string_begin and res.kmer_offset < res.string_end - k + 1) return true; return false; } }; diff --git a/test/test_encoded_boundaries.cpp b/test/test_encoded_boundaries.cpp new file mode 100644 index 0000000..3812939 --- /dev/null +++ b/test/test_encoded_boundaries.cpp @@ -0,0 +1,71 @@ +#include +#include +#include + +#include "src/builder/build.cpp" +#include "src/dictionary.cpp" +#include "src/info.cpp" + +using namespace sshash; + +struct test_directory { + std::filesystem::path path = + std::filesystem::temp_directory_path() / + ("sshash-boundaries-" + + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())); + + test_directory() { std::filesystem::create_directory(path); } + ~test_directory() { + std::error_code error; + std::filesystem::remove_all(path, error); + } +}; + +using dict_type = dictionary, encoded_offsets>; + +void verify(dict_type const& dict, std::vector const& strings) { + // The reverse complement TCGTC spans the second/third string boundary. + if (dict.lookup("GACGA").kmer_id != constants::invalid_uint64) { + throw std::runtime_error("absent k-mer GACGA reported present"); + } + uint64_t kmer_id = 0; + for (auto const& string : strings) { + for (uint64_t i = 0; i + dict.k() <= string.size(); ++i, ++kmer_id) { + if (dict.lookup(string.data() + i).kmer_id != kmer_id) { + throw std::runtime_error("stored k-mer lost at string boundary"); + } + } + } +} + +int main() { + try { + test_directory directory; + std::vector strings = {"CGGGGGC", "GTGTATT", "CGTCAGA", "CCACGAA"}; + auto input = directory.path / "input.fa"; + { + std::ofstream out(input); + out.exceptions(std::ios::failbit | std::ios::badbit); + for (auto const& string : strings) out << ">test\n" << string << '\n'; + } + build_configuration config; + config.k = 5; + config.m = 1; + config.verbose = false; + config.tmp_dirname = directory.path.string(); + dict_type dict; + dict.build(input.string(), config); + verify(dict, strings); + + std::stringstream bytes; + essentials::generic_saver saver(bytes); + saver.visit(dict); + dict_type loaded; + essentials::generic_loader loader(bytes); + loader.visit(loaded); + verify(loaded, strings); + } catch (std::exception const& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} From aff189bedb1a6588f2b5b662657b5781c5bb7205 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Fri, 23 Oct 2026 23:36:29 +0200 Subject: [PATCH 2/7] Move shared CI setup to its own proposal --- .github/workflows/build.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4799869..59b261d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,6 @@ jobs: build: strategy: matrix: - build_type: [Release] compiler: - { name: gcc, version: 11} - { name: gcc, version: 12} @@ -17,10 +16,7 @@ jobs: - { name: clang, version: 16} - { name: clang, version: 17} - { name: clang, version: 18} - include: - - compiler: { name: gcc, version: 14} - build_type: Debug - name: Build (${{ matrix.compiler.name }} ${{ matrix.compiler.version }})${{ matrix.build_type == 'Debug' && ' with assertions' || '' }} + name: Build (${{ matrix.compiler.name }} ${{ matrix.compiler.version }}) runs-on: ubuntu-latest steps: - name: Install dependencies @@ -45,6 +41,5 @@ jobs: submodules: recursive - name: Build run: | - cmake -B ./build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + cmake -B ./build cmake --build ./build --parallel - ctest --test-dir ./build --output-on-failure From c8df4925a5d7c8e1cf6509b583fe0d4a077223e5 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Fri, 23 Oct 2026 23:45:02 +0200 Subject: [PATCH 3/7] Keep shared testing configuration in the CI proposal --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31744a5..5e8d316 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,8 +90,6 @@ target_link_libraries(sshash_static PUBLIC ZLIB::ZLIB) add_library(sshash::sshash ALIAS sshash_static) if (SSHASH_BUILD_EXECUTABLES) - enable_testing() - add_executable(sshash tools/sshash.cpp) target_link_libraries(sshash PRIVATE sshash_static) From 024fcc9720347cf046bde0ab6f8b93e94690eae1 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Sat, 24 Oct 2026 00:23:51 +0200 Subject: [PATCH 4/7] Keep the boundary regression focused on lookup --- test/test_encoded_boundaries.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/test_encoded_boundaries.cpp b/test/test_encoded_boundaries.cpp index 3812939..0c98c50 100644 --- a/test/test_encoded_boundaries.cpp +++ b/test/test_encoded_boundaries.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "src/builder/build.cpp" #include "src/dictionary.cpp" @@ -56,14 +55,6 @@ int main() { dict_type dict; dict.build(input.string(), config); verify(dict, strings); - - std::stringstream bytes; - essentials::generic_saver saver(bytes); - saver.visit(dict); - dict_type loaded; - essentials::generic_loader loader(bytes); - loader.visit(loaded); - verify(loaded, strings); } catch (std::exception const& error) { std::cerr << error.what() << '\n'; return 1; From 2392a968fa0285c6fc2b6b9934714b8a239505ac Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 4 Nov 2026 23:00:12 +0100 Subject: [PATCH 5/7] Isolate regression target registration from other proposals --- CMakeLists.txt | 10 ++++++---- test/cmake/97.cmake | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 test/cmake/97.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index cb26a88..75c793b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,13 +103,15 @@ if (SSHASH_BUILD_EXECUTABLES) target_link_libraries(test_minimizer PRIVATE sshash_static) add_test(NAME minimizer COMMAND test_minimizer) + # Keep independently contributed regression targets in separate files. + file(GLOB SSHASH_TEST_REGISTRATIONS "${CMAKE_CURRENT_SOURCE_DIR}/test/cmake/*.cmake") + foreach(registration IN LISTS SSHASH_TEST_REGISTRATIONS) + include("${registration}") + endforeach() + add_executable(check test/check.cpp) target_link_libraries(check PRIVATE sshash_static) - add_executable(test_encoded_boundaries test/test_encoded_boundaries.cpp) - target_link_libraries(test_encoded_boundaries PRIVATE sshash_static) - add_test(NAME encoded_boundaries COMMAND test_encoded_boundaries) - if (CONDA_BUILD) install(TARGETS sshash RUNTIME DESTINATION bin) endif () diff --git a/test/cmake/97.cmake b/test/cmake/97.cmake new file mode 100644 index 0000000..dacdf76 --- /dev/null +++ b/test/cmake/97.cmake @@ -0,0 +1,3 @@ +add_executable(test_encoded_boundaries test/test_encoded_boundaries.cpp) +target_link_libraries(test_encoded_boundaries PRIVATE sshash_static) +add_test(NAME encoded_boundaries COMMAND test_encoded_boundaries) From 7eae38ce018254517afe397b575f9baef2806986 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 4 Nov 2026 23:00:29 +0100 Subject: [PATCH 6/7] Name regression registration by feature --- test/cmake/{97.cmake => encoded_boundaries.cmake} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/cmake/{97.cmake => encoded_boundaries.cmake} (100%) diff --git a/test/cmake/97.cmake b/test/cmake/encoded_boundaries.cmake similarity index 100% rename from test/cmake/97.cmake rename to test/cmake/encoded_boundaries.cmake From 03da7d17e1a6fd28edfe7ddc4f130650e8b2d3f9 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Wed, 4 Nov 2026 23:02:29 +0100 Subject: [PATCH 7/7] Refresh regression registration when files are added --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75c793b..fa00d24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,7 +104,12 @@ if (SSHASH_BUILD_EXECUTABLES) add_test(NAME minimizer COMMAND test_minimizer) # Keep independently contributed regression targets in separate files. - file(GLOB SSHASH_TEST_REGISTRATIONS "${CMAKE_CURRENT_SOURCE_DIR}/test/cmake/*.cmake") + set(SSHASH_TEST_GLOB_OPTIONS) + if(NOT CMAKE_VERSION VERSION_LESS "3.12") + list(APPEND SSHASH_TEST_GLOB_OPTIONS CONFIGURE_DEPENDS) + endif() + file(GLOB SSHASH_TEST_REGISTRATIONS ${SSHASH_TEST_GLOB_OPTIONS} + "${CMAKE_CURRENT_SOURCE_DIR}/test/cmake/*.cmake") foreach(registration IN LISTS SSHASH_TEST_REGISTRATIONS) include("${registration}") endforeach()