Number of tests is now 6
This commit is contained in:
parent
a4cadedffe
commit
4d03dcd545
@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.1)
|
||||||
|
|
||||||
# set directory name as the project name
|
# set directory name as the project name
|
||||||
# get directory name
|
# get directory name
|
||||||
|
@ -9,20 +9,20 @@ namespace lockfree
|
|||||||
{
|
{
|
||||||
|
|
||||||
template <class K, class V>
|
template <class K, class V>
|
||||||
class HashMap: Lockable<SpinLock>
|
class HashMap : Lockable<SpinLock>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
V at(const K& key)
|
V at(const K& key)
|
||||||
{
|
{
|
||||||
auto guard = acquire();
|
auto guard = acquire_unique();
|
||||||
|
|
||||||
return hashmap[key];
|
return hashmap[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
void put(const K& key, const K& value)
|
void put(const K& key, const K& value)
|
||||||
{
|
{
|
||||||
auto quard = acquire();
|
auto guard = acquire_unique();
|
||||||
|
|
||||||
hashmap[key] = value;
|
hashmap[key] = value;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include "utils/log/logger.hpp"
|
#include "utils/log/logger.hpp"
|
||||||
|
|
||||||
@ -110,8 +111,9 @@ public:
|
|||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
|
is_running.store(true);
|
||||||
run_thread = std::thread([this]() {
|
run_thread = std::thread([this]() {
|
||||||
while (true) {
|
while (is_running.load()) {
|
||||||
std::this_thread::sleep_for(delta_time_type(delta_time));
|
std::this_thread::sleep_for(delta_time_type(delta_time));
|
||||||
timer_container.process();
|
timer_container.process();
|
||||||
LOG_INFO("timer_container.process()");
|
LOG_INFO("timer_container.process()");
|
||||||
@ -119,6 +121,11 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stop()
|
||||||
|
{
|
||||||
|
is_running.store(false);
|
||||||
|
}
|
||||||
|
|
||||||
~TimerScheduler()
|
~TimerScheduler()
|
||||||
{
|
{
|
||||||
run_thread.join();
|
run_thread.join();
|
||||||
@ -128,4 +135,5 @@ public:
|
|||||||
private:
|
private:
|
||||||
timer_container_type timer_container;
|
timer_container_type timer_container;
|
||||||
std::thread run_thread;
|
std::thread run_thread;
|
||||||
|
std::atomic<bool> is_running;
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.1)
|
||||||
|
|
||||||
project(memgraph_tests)
|
project(memgraph_tests)
|
||||||
|
|
||||||
# setup dependencies
|
# setup dependencies
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
# Catch (C++ Automated Test Cases in Headers) dependency
|
# Catch (C++ Automated Test Cases in Headers) dependency
|
||||||
ExternalProject_Add(
|
ExternalProject_Add(
|
||||||
@ -35,8 +36,10 @@ file(COPY ${CMAKE_SOURCE_DIR}/tests/data DESTINATION ${CMAKE_BINARY_DIR}/tests)
|
|||||||
# build tests
|
# build tests
|
||||||
foreach(test ${tests})
|
foreach(test ${tests})
|
||||||
add_executable(${test} ${test}.cpp)
|
add_executable(${test} ${test}.cpp)
|
||||||
|
# TODO: separate dependencies
|
||||||
target_link_libraries(${test} stdc++fs)
|
target_link_libraries(${test} stdc++fs)
|
||||||
target_link_libraries(${test} cypher_lib)
|
target_link_libraries(${test} cypher_lib)
|
||||||
|
target_link_libraries(${test} Threads::Threads)
|
||||||
add_test(NAME ${test} COMMAND ${test})
|
add_test(NAME ${test} COMMAND ${test})
|
||||||
set_property(TARGET ${test} PROPERTY CXX_STANDARD 14)
|
set_property(TARGET ${test} PROPERTY CXX_STANDARD 14)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
#define CATCH_CONFIG_MAIN
|
|
||||||
#include "catch.hpp"
|
|
||||||
|
|
||||||
TEST_CASE("Dummy test")
|
|
||||||
{
|
|
||||||
REQUIRE(true == true);
|
|
||||||
}
|
|
@ -1,4 +1,6 @@
|
|||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
#include "data_structures/map/hashmap.hpp"
|
#include "data_structures/map/hashmap.hpp"
|
||||||
|
|
||||||
TEST_CASE("Lockfree HashMap basic functionality")
|
TEST_CASE("Lockfree HashMap basic functionality")
|
60
tests/skiplist.cpp
Normal file
60
tests/skiplist.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "data_structures/skiplist/skiplist.hpp"
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
|
using skiplist_t = SkipList<int, int>;
|
||||||
|
|
||||||
|
void print_skiplist(const skiplist_t::Accessor& skiplist)
|
||||||
|
{
|
||||||
|
cout << "---- skiplist now has: ";
|
||||||
|
|
||||||
|
for(auto& kv : skiplist)
|
||||||
|
cout << "(" << kv.first << ", " << kv.second << ") ";
|
||||||
|
|
||||||
|
cout << "----" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
skiplist_t skiplist;
|
||||||
|
auto accessor = skiplist.access();
|
||||||
|
|
||||||
|
// insert 10
|
||||||
|
assert(accessor.insert_unique(1, 10).second == true);
|
||||||
|
|
||||||
|
// try insert 10 again (should fail)
|
||||||
|
assert(accessor.insert_unique(1, 10).second == false);
|
||||||
|
|
||||||
|
// insert 20
|
||||||
|
assert(accessor.insert_unique(2, 20).second == true);
|
||||||
|
|
||||||
|
print_skiplist(accessor);
|
||||||
|
|
||||||
|
// value at key 3 shouldn't exist
|
||||||
|
assert((accessor.find(3) == accessor.end()) == true);
|
||||||
|
|
||||||
|
// value at key 2 should exist
|
||||||
|
assert((accessor.find(2) != accessor.end()) == true);
|
||||||
|
|
||||||
|
// at key 2 is 20 (true)
|
||||||
|
assert(accessor.find(2)->second == 20);
|
||||||
|
|
||||||
|
// removed existing (1)
|
||||||
|
assert(accessor.remove(1) == true);
|
||||||
|
|
||||||
|
// removed non-existing (3)
|
||||||
|
assert(accessor.remove(3) == false);
|
||||||
|
|
||||||
|
// insert (1, 10)
|
||||||
|
assert(accessor.insert_unique(1, 10).second == true);
|
||||||
|
|
||||||
|
// insert (4, 40)
|
||||||
|
assert(accessor.insert_unique(4, 40).second == true);
|
||||||
|
|
||||||
|
print_skiplist(accessor);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,9 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
// #define NOT_LOG_INFO
|
|
||||||
// compile this with: c++ -std=c++1y -o a.out -I../../../ -pthread main.cpp
|
|
||||||
|
|
||||||
#include "utils/log/logger.hpp"
|
#include "utils/log/logger.hpp"
|
||||||
#include "utils/timer/timer.hpp"
|
#include "utils/timer/timer.hpp"
|
||||||
|
|
||||||
@ -23,7 +20,9 @@ int main(void)
|
|||||||
for (int64_t i = 1; i <= 3; ++i) {
|
for (int64_t i = 1; i <= 3; ++i) {
|
||||||
timer_scheduler.add(create_test_timer(i));
|
timer_scheduler.add(create_test_timer(i));
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(10s);
|
std::this_thread::sleep_for(4s);
|
||||||
timer_scheduler.add(create_test_timer(1));
|
timer_scheduler.add(create_test_timer(1));
|
||||||
|
std::this_thread::sleep_for(2s);
|
||||||
|
timer_scheduler.stop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user