memgraph/tests/unit/concurrent_map.cpp
Kruno Tomola Fabro df0bf6fa5f Database interface refactor.
DbAccessor:
 -Guarantees that access to Vertex and Edge is possible only through
 Vertex::Accessor and Edge::Accessor.
 -Guarantees that changing Vertex and Edge is possible only using
 Vertex::Accessor returned by vertex_insert() method and
 Edge::Accessor returned by edge_insert() method.
 -Offers CRUD for Vertex and Edge except iterating over all edges.

Squashed commit messages:

First step in database accessor refactoring done.
It's compiling.
All tests with exception of integration_querys pass

Tests now initialize logging facilities.

Refactored accessors.
RecordAccessor now has 3 states.
From,To,Out,In in there respecive Accessors return unfilled RecordAccessor.
Added iterator classes into utils/itearator/.
2016-08-15 00:09:58 +01:00

74 lines
2.0 KiB
C++

#include <iostream>
#include "data_structures/concurrent/concurrent_map.hpp"
#include "logging/default.hpp"
#include "logging/streams/stdout.hpp"
#include "utils/assert.hpp"
using std::cout;
using std::endl;
using skiplist_t = ConcurrentMap<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)
{
logging::init_async();
logging::log->pipe(std::make_unique<Stdout>());
skiplist_t skiplist;
auto accessor = skiplist.access();
// insert 10
permanent_assert(accessor.insert(1, 10).second == true,
"add first element");
// try insert 10 again (should fail)
permanent_assert(accessor.insert(1, 10).second == false,
"add the same element, should fail");
// insert 20
permanent_assert(accessor.insert(2, 20).second == true,
"insert new unique element");
print_skiplist(accessor);
// value at key 3 shouldn't exist
permanent_assert((accessor.find(3) == accessor.end()) == true,
"try to find element which doesn't exist");
// value at key 2 should exist
permanent_assert((accessor.find(2) != accessor.end()) == true,
"find iterator");
// at key 2 is 20 (true)
permanent_assert(accessor.find(2)->second == 20, "find element");
// removed existing (1)
permanent_assert(accessor.remove(1) == true, "try to remove element");
// removed non-existing (3)
permanent_assert(accessor.remove(3) == false,
"try to remove element which doesn't exist");
// insert (1, 10)
permanent_assert(accessor.insert(1, 10).second == true,
"insert unique element");
// insert (4, 40)
permanent_assert(accessor.insert(4, 40).second == true,
"insert unique element");
print_skiplist(accessor);
return 0;
}