logger update, stderr stream is added

This commit is contained in:
Marko Budiselic
2016-08-14 12:43:34 +01:00
parent 2113546b9c
commit a3a8dc7c28
6 changed files with 96 additions and 49 deletions

View File

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