Skip to content
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ 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.
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()

add_executable(check test/check.cpp)
target_link_libraries(check PRIVATE sshash_static)

Expand Down
2 changes: 1 addition & 1 deletion include/spectrum_preserving_string_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
3 changes: 3 additions & 0 deletions test/cmake/encoded_boundaries.cmake
Original file line number Diff line number Diff line change
@@ -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)
62 changes: 62 additions & 0 deletions test/test_encoded_boundaries.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <chrono>
#include <filesystem>

#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<dna_uint_kmer_t<uint64_t>, encoded_offsets>;

void verify(dict_type const& dict, std::vector<std::string> 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<std::string> 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);
} catch (std::exception const& error) {
std::cerr << error.what() << '\n';
return 1;
}
}
Loading