fix the test
This commit is contained in:
parent
f616fd6008
commit
62129f4b29
|
@ -21,7 +21,6 @@ else ()
|
||||||
message(STATUS "Compiler is recent enough to support C++17.")
|
message(STATUS "Compiler is recent enough to support C++17.")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -pthread -msse4.2 -mbmi2 -Wall")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -pthread -Wall")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -pthread -Wall")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -march=native -O3")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -march=native -O3")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -O0 -g -DDEBUG")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -O0 -g -DDEBUG")
|
||||||
|
@ -40,5 +39,4 @@ add_subdirectory(tools)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
||||||
|
|
||||||
file(COPY ${CMAKE_SOURCE_DIR}/tests/keys.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/tests)
|
file(COPY ${CMAKE_SOURCE_DIR}/tests/keys.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/tests)
|
||||||
|
|
|
@ -33,7 +33,7 @@ class bc_vector_8 {
|
||||||
template <class BcUnits>
|
template <class BcUnits>
|
||||||
explicit bc_vector_8(const BcUnits& bc_units, bit_vector::builder&& leaves) {
|
explicit bc_vector_8(const BcUnits& bc_units, bit_vector::builder&& leaves) {
|
||||||
std::array<std::vector<std::uint8_t>, max_levels> bytes;
|
std::array<std::vector<std::uint8_t>, max_levels> bytes;
|
||||||
std::array<bit_vector::builder, max_levels - 1> next_flags;
|
std::array<bit_vector::builder, max_levels> next_flags; // The last will not be released
|
||||||
std::vector<std::uint64_t> links;
|
std::vector<std::uint64_t> links;
|
||||||
|
|
||||||
bytes[0].reserve(bc_units.size() * 2);
|
bytes[0].reserve(bc_units.size() * 2);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
namespace xcdat {
|
namespace xcdat {
|
||||||
|
|
||||||
|
// Vigna's Rank9 implementation from https://github.com/ot/succinct.
|
||||||
class bit_vector {
|
class bit_vector {
|
||||||
public:
|
public:
|
||||||
class builder {
|
class builder {
|
||||||
|
|
|
@ -1,6 +1,24 @@
|
||||||
file(GLOB TEST_SOURCES test_*.cpp)
|
add_executable(test_bit_vector test_bit_vector.cpp)
|
||||||
foreach(TEST_SOURCE ${TEST_SOURCES})
|
add_test(test_bit_vector test_bit_vector)
|
||||||
get_filename_component(TEST_SOURCE_NAME ${TEST_SOURCE} NAME_WE)
|
|
||||||
add_executable(${TEST_SOURCE_NAME} ${TEST_SOURCE})
|
add_executable(test_compact_vector test_compact_vector.cpp)
|
||||||
add_test(${TEST_SOURCE_NAME} ${TEST_SOURCE_NAME})
|
add_test(test_compact_vector test_compact_vector)
|
||||||
endforeach()
|
|
||||||
|
add_executable(test_tail_vector test_tail_vector.cpp)
|
||||||
|
add_test(test_tail_vector test_tail_vector)
|
||||||
|
|
||||||
|
set(BC_OPTIONS "7" "8")
|
||||||
|
|
||||||
|
foreach(BC_OPTION ${BC_OPTIONS})
|
||||||
|
set(TEST_SRC_NAME test_bc_vector_${BC_OPTION})
|
||||||
|
add_executable(${TEST_SRC_NAME} test_bc_vector.cpp)
|
||||||
|
set_target_properties(${TEST_SRC_NAME} PROPERTIES COMPILE_DEFINITIONS BC_VECTOR_${BC_OPTION})
|
||||||
|
add_test(${TEST_SRC_NAME} ${TEST_SRC_NAME})
|
||||||
|
endforeach(BC_OPTION)
|
||||||
|
|
||||||
|
foreach(BC_OPTION ${BC_OPTIONS})
|
||||||
|
set(TEST_SRC_NAME test_trie_${BC_OPTION})
|
||||||
|
add_executable(${TEST_SRC_NAME} test_trie.cpp)
|
||||||
|
set_target_properties(${TEST_SRC_NAME} PROPERTIES COMPILE_DEFINITIONS TRIE_${BC_OPTION})
|
||||||
|
add_test(${TEST_SRC_NAME} ${TEST_SRC_NAME})
|
||||||
|
endforeach(BC_OPTION)
|
||||||
|
|
|
@ -8,8 +8,11 @@
|
||||||
#include "xcdat/bc_vector_7.hpp"
|
#include "xcdat/bc_vector_7.hpp"
|
||||||
#include "xcdat/bc_vector_8.hpp"
|
#include "xcdat/bc_vector_8.hpp"
|
||||||
|
|
||||||
|
#ifdef BC_VECTOR_7
|
||||||
using bc_vector_type = xcdat::bc_vector_7;
|
using bc_vector_type = xcdat::bc_vector_7;
|
||||||
// using bc_vector_type = xcdat::bc_vector_8;
|
#elif BC_VECTOR_8
|
||||||
|
using bc_vector_type = xcdat::bc_vector_8;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct bc_unit {
|
struct bc_unit {
|
||||||
std::uint64_t base;
|
std::uint64_t base;
|
||||||
|
|
|
@ -6,11 +6,15 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "doctest/doctest.h"
|
#include "doctest/doctest.h"
|
||||||
|
#include "mm_file/mm_file.hpp"
|
||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
#include "xcdat.hpp"
|
#include "xcdat.hpp"
|
||||||
|
|
||||||
|
#ifdef TRIE_7
|
||||||
using trie_type = xcdat::trie_7_type;
|
using trie_type = xcdat::trie_7_type;
|
||||||
// using trie_type = xcdat::trie_8_type;
|
#elif TRIE_8
|
||||||
|
using trie_type = xcdat::trie_8_type;
|
||||||
|
#endif
|
||||||
|
|
||||||
void test_basic_operations(const trie_type& trie, const std::vector<std::string>& keys,
|
void test_basic_operations(const trie_type& trie, const std::vector<std::string>& keys,
|
||||||
const std::vector<std::string>& others) {
|
const std::vector<std::string>& others) {
|
||||||
|
@ -115,6 +119,36 @@ void test_enumerate(const trie_type& trie, const std::vector<std::string>& keys)
|
||||||
REQUIRE_FALSE(itr.next());
|
REQUIRE_FALSE(itr.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_io(const trie_type& trie, const std::vector<std::string>& keys, const std::vector<std::string>& others) {
|
||||||
|
const char* tmp_filepath = "tmp.idx";
|
||||||
|
|
||||||
|
const std::uint64_t memory = xcdat::memory_in_bytes(trie);
|
||||||
|
REQUIRE_EQ(memory, xcdat::save(trie, tmp_filepath));
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto loaded = xcdat::load<trie_type>(tmp_filepath);
|
||||||
|
REQUIRE_EQ(trie.bin_mode(), loaded.bin_mode());
|
||||||
|
REQUIRE_EQ(trie.num_keys(), loaded.num_keys());
|
||||||
|
REQUIRE_EQ(trie.alphabet_size(), loaded.alphabet_size());
|
||||||
|
REQUIRE_EQ(trie.max_length(), loaded.max_length());
|
||||||
|
REQUIRE_EQ(memory, xcdat::memory_in_bytes(loaded));
|
||||||
|
test_basic_operations(loaded, keys, others);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
mm::file_source<char> fin(tmp_filepath, mm::advice::sequential);
|
||||||
|
const auto mapped = xcdat::mmap<trie_type>(fin.data());
|
||||||
|
REQUIRE_EQ(trie.bin_mode(), mapped.bin_mode());
|
||||||
|
REQUIRE_EQ(trie.num_keys(), mapped.num_keys());
|
||||||
|
REQUIRE_EQ(trie.alphabet_size(), mapped.alphabet_size());
|
||||||
|
REQUIRE_EQ(trie.max_length(), mapped.max_length());
|
||||||
|
REQUIRE_EQ(memory, xcdat::memory_in_bytes(mapped));
|
||||||
|
test_basic_operations(mapped, keys, others);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::remove(tmp_filepath);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("Test trie_type (tiny)") {
|
TEST_CASE("Test trie_type (tiny)") {
|
||||||
std::vector<std::string> keys = {
|
std::vector<std::string> keys = {
|
||||||
"AirPods", "AirTag", "Mac", "MacBook", "MacBook_Air", "MacBook_Pro",
|
"AirPods", "AirTag", "Mac", "MacBook", "MacBook_Air", "MacBook_Pro",
|
||||||
|
@ -128,6 +162,7 @@ TEST_CASE("Test trie_type (tiny)") {
|
||||||
REQUIRE_FALSE(trie.bin_mode());
|
REQUIRE_FALSE(trie.bin_mode());
|
||||||
|
|
||||||
test_basic_operations(trie, keys, others);
|
test_basic_operations(trie, keys, others);
|
||||||
|
|
||||||
{
|
{
|
||||||
auto itr = trie.make_prefix_iterator("MacBook_Pro");
|
auto itr = trie.make_prefix_iterator("MacBook_Pro");
|
||||||
std::vector<std::string> expected = {"Mac", "MacBook", "MacBook_Pro"};
|
std::vector<std::string> expected = {"Mac", "MacBook", "MacBook_Pro"};
|
||||||
|
@ -157,6 +192,8 @@ TEST_CASE("Test trie_type (tiny)") {
|
||||||
}
|
}
|
||||||
REQUIRE_FALSE(itr.next());
|
REQUIRE_FALSE(itr.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_io(trie, keys, others);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test trie_type (real)") {
|
TEST_CASE("Test trie_type (real)") {
|
||||||
|
@ -170,6 +207,7 @@ TEST_CASE("Test trie_type (real)") {
|
||||||
test_prefix_search(trie, keys, others);
|
test_prefix_search(trie, keys, others);
|
||||||
test_predictive_search(trie, keys, others);
|
test_predictive_search(trie, keys, others);
|
||||||
test_enumerate(trie, keys);
|
test_enumerate(trie, keys);
|
||||||
|
test_io(trie, keys, others);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test trie_type (random 10K, A--B)") {
|
TEST_CASE("Test trie_type (random 10K, A--B)") {
|
||||||
|
@ -183,6 +221,7 @@ TEST_CASE("Test trie_type (random 10K, A--B)") {
|
||||||
test_prefix_search(trie, keys, others);
|
test_prefix_search(trie, keys, others);
|
||||||
test_predictive_search(trie, keys, others);
|
test_predictive_search(trie, keys, others);
|
||||||
test_enumerate(trie, keys);
|
test_enumerate(trie, keys);
|
||||||
|
test_io(trie, keys, others);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test trie_type (random 10K, A--Z)") {
|
TEST_CASE("Test trie_type (random 10K, A--Z)") {
|
||||||
|
@ -196,6 +235,7 @@ TEST_CASE("Test trie_type (random 10K, A--Z)") {
|
||||||
test_prefix_search(trie, keys, others);
|
test_prefix_search(trie, keys, others);
|
||||||
test_predictive_search(trie, keys, others);
|
test_predictive_search(trie, keys, others);
|
||||||
test_enumerate(trie, keys);
|
test_enumerate(trie, keys);
|
||||||
|
test_io(trie, keys, others);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test trie_type (random 10K, 0x00--0xFF)") {
|
TEST_CASE("Test trie_type (random 10K, 0x00--0xFF)") {
|
||||||
|
@ -209,6 +249,7 @@ TEST_CASE("Test trie_type (random 10K, 0x00--0xFF)") {
|
||||||
test_prefix_search(trie, keys, others);
|
test_prefix_search(trie, keys, others);
|
||||||
test_predictive_search(trie, keys, others);
|
test_predictive_search(trie, keys, others);
|
||||||
test_enumerate(trie, keys);
|
test_enumerate(trie, keys);
|
||||||
|
test_io(trie, keys, others);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
|
@ -223,6 +264,7 @@ TEST_CASE("Test trie_type (random 100K, A--B)") {
|
||||||
test_prefix_search(trie, keys, others);
|
test_prefix_search(trie, keys, others);
|
||||||
test_predictive_search(trie, keys, others);
|
test_predictive_search(trie, keys, others);
|
||||||
test_enumerate(trie, keys);
|
test_enumerate(trie, keys);
|
||||||
|
test_io(trie, keys, others);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test trie_type (random 100K, A--Z)") {
|
TEST_CASE("Test trie_type (random 100K, A--Z)") {
|
||||||
|
@ -236,6 +278,7 @@ TEST_CASE("Test trie_type (random 100K, A--Z)") {
|
||||||
test_prefix_search(trie, keys, others);
|
test_prefix_search(trie, keys, others);
|
||||||
test_predictive_search(trie, keys, others);
|
test_predictive_search(trie, keys, others);
|
||||||
test_enumerate(trie, keys);
|
test_enumerate(trie, keys);
|
||||||
|
test_io(trie, keys, others);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test trie_type (random 100K, 0x00--0xFF)") {
|
TEST_CASE("Test trie_type (random 100K, 0x00--0xFF)") {
|
||||||
|
@ -249,5 +292,6 @@ TEST_CASE("Test trie_type (random 100K, 0x00--0xFF)") {
|
||||||
test_prefix_search(trie, keys, others);
|
test_prefix_search(trie, keys, others);
|
||||||
test_predictive_search(trie, keys, others);
|
test_predictive_search(trie, keys, others);
|
||||||
test_enumerate(trie, keys);
|
test_enumerate(trie, keys);
|
||||||
|
test_io(trie, keys, others);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
Loading…
Reference in a new issue