added tests
This commit is contained in:
parent
0e1e55ffb1
commit
e2ae589a0e
@ -7,6 +7,30 @@ set(CMAKE_C_FLAGS_DEBUG "-g -O0 -fPIC" CACHE STRING "Debug flags" FORCE)
|
||||
|
||||
include_directories(${sharedMemoryKeyDB_SOURCE_DIR})
|
||||
|
||||
option(BUILD_TESTS "Build unit tests" ON)
|
||||
|
||||
if (BUILD_TESTS)
|
||||
# enable_testing()
|
||||
#
|
||||
# include(FetchContent)
|
||||
# FetchContent_Declare(
|
||||
# googletest
|
||||
# URL https://github.com/google/googletest/archive/refs/heads/main.zip
|
||||
# )
|
||||
# FetchContent_MakeAvailable(googletest)
|
||||
#
|
||||
# add_executable(tests
|
||||
# tests/test_1.cpp
|
||||
# )
|
||||
#
|
||||
# target_link_libraries(my_tests
|
||||
# gtest_main
|
||||
# )
|
||||
#
|
||||
# include(GoogleTest)
|
||||
# gtest_discover_tests(my_tests)
|
||||
endif()
|
||||
|
||||
add_executable(sharedMemoryKeyDB
|
||||
main.cpp
|
||||
utils/toml/toml.hpp
|
||||
|
65
tests/test_1.cpp
Normal file
65
tests/test_1.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// Created by Kirill Zhukov on 20.04.2025.
|
||||
//
|
||||
|
||||
|
||||
|
||||
TEST(SkipListTests, BasicOperations) {
|
||||
std::string db_name = "test_db";
|
||||
VersionManager version_manager(db_name);
|
||||
LFSkipList<Hash128, std::string> table(version_manager);
|
||||
|
||||
table.insert(compute_hash128("a", 1), "apple");
|
||||
table.insert(compute_hash128("b", 1), "banana");
|
||||
table.insert(compute_hash128("c", 1), "cherry");
|
||||
|
||||
auto a = table.find(compute_hash128("a", 1));
|
||||
auto b = table.find(compute_hash128("b", 1));
|
||||
auto c = table.find(compute_hash128("c", 1));
|
||||
auto d = table.find(compute_hash128("d", 1));
|
||||
|
||||
ASSERT_TRUE(a.has_value());
|
||||
EXPECT_EQ(a.value(), "apple");
|
||||
|
||||
ASSERT_TRUE(b.has_value());
|
||||
EXPECT_EQ(b.value(), "banana");
|
||||
|
||||
ASSERT_TRUE(c.has_value());
|
||||
EXPECT_EQ(c.value(), "cherry");
|
||||
|
||||
ASSERT_FALSE(d.has_value());
|
||||
}
|
||||
|
||||
TEST(VersionManagerTests, PersistenceAcrossRestarts) {
|
||||
std::string db_name = "test_db";
|
||||
{
|
||||
VersionManager vm1(db_name);
|
||||
(void)vm1.next_version();
|
||||
(void)vm1.next_version();
|
||||
(void)vm1.next_version();
|
||||
}
|
||||
|
||||
VersionManager vm2(db_name);
|
||||
uint64_t v4 = vm2.next_version();
|
||||
|
||||
ASSERT_GT(v4, 3u) << "Version did not persist correctly";
|
||||
}
|
||||
|
||||
TEST(SSTableTests, WriteAndRead) {
|
||||
std::string db_name = "test_db";
|
||||
VersionManager version_manager(db_name);
|
||||
|
||||
LFSkipList<Hash128, std::string> table(version_manager);
|
||||
table.insert(compute_hash128("dog", 3), "bark");
|
||||
table.insert(compute_hash128("cat", 3), "meow");
|
||||
table.insert(compute_hash128("cow", 3), "moo");
|
||||
|
||||
write_sstable_with_index(table, "test_sstable.dat");
|
||||
|
||||
LFSkipList<Hash128, std::string> loaded_table(version_manager);
|
||||
read_sstable_with_mmap(loaded_table, "test_sstable.dat");
|
||||
|
||||
ASSERT_TRUE(loaded_table.find(compute_hash128("dog", 3)).has_value());
|
||||
ASSERT_TRUE(loaded_table.find(compute_hash128("cat", 3)).has_value());
|
||||
ASSERT_TRUE(loaded_table.find(compute_hash128("cow", 3)).has_value());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user