2016-07-05 11:01:22 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-06-21 17:29:13 +08:00
|
|
|
#include <glog/logging.h>
|
|
|
|
#include <gtest/gtest.h>
|
2016-12-23 02:28:21 +08:00
|
|
|
|
2016-07-05 11:01:22 +08:00
|
|
|
#include "data_structures/concurrent/concurrent_set.hpp"
|
|
|
|
#include "utils/assert.hpp"
|
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
void print_skiplist(const ConcurrentSet<int>::Accessor &skiplist) {
|
2017-06-21 17:29:13 +08:00
|
|
|
DLOG(INFO) << "Skiplist set now has:";
|
|
|
|
for (auto &item : skiplist) DLOG(INFO) << item;
|
2016-07-05 11:01:22 +08:00
|
|
|
}
|
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
TEST(ConcurrentSet, Mix) {
|
|
|
|
ConcurrentSet<int> set;
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
auto accessor = set.access();
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(accessor.insert(1).second == true,
|
|
|
|
"added non-existing 1? (true)");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(accessor.insert(1).second == false,
|
|
|
|
"added already existing 1? (false)");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(accessor.insert(2).second == true,
|
|
|
|
"added non-existing 2? (true)");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(accessor.find(3) == accessor.end(),
|
|
|
|
"item 3 doesn't exist? (true)");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(accessor.contains(3) == false, "item 3 exists? (false)");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(accessor.find(2) != accessor.end(), "item 2 exists? (true)");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(*accessor.find(2) == 2, "find item 2");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(accessor.remove(1) == true, "removed existing 1? (true)");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(accessor.remove(3) == false,
|
|
|
|
"try to remove non existing element");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(accessor.insert(1).second == true, "add 1 again");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
permanent_assert(accessor.insert(4).second == true, "add 4");
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
print_skiplist(accessor);
|
2016-12-23 02:28:21 +08:00
|
|
|
}
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
int main(int argc, char **argv) {
|
2017-06-21 17:29:13 +08:00
|
|
|
google::InitGoogleLogging(argv[0]);
|
2017-02-18 18:54:37 +08:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
2016-07-05 11:01:22 +08:00
|
|
|
}
|