memgraph/tests/unit/concurrent_map_access.cpp
Dominik Gleich ebc7b2b1b9 Const map/set iteration.
Summary: In the current state, it was not possible to iterate, or even access a const map, or const set structure because of an incorrect implementation of "ConstAccessors".

Reviewers: mislav.bradac, teon.banek, buda

Reviewed By: teon.banek, buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D902
2017-10-12 16:35:39 +02:00

48 lines
1.1 KiB
C++

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <vector>
#include "data_structures/concurrent/concurrent_map.hpp"
TEST(ConcurrentMap, Access) {
ConcurrentMap<int, int> input;
{
auto accessor = input.access();
accessor.insert(1, 1);
accessor.insert(2, 2);
accessor.insert(3, 3);
}
auto accessor = input.access();
std::vector<int> results;
for (auto it = accessor.begin(); it != accessor.end(); ++it)
results.push_back(it->first);
EXPECT_THAT(results, testing::ElementsAre(1, 2, 3));
}
TEST(ConcurrentMap, ConstAccess) {
ConcurrentMap<int, int> input;
{
auto accessor = input.access();
accessor.insert(1, 1);
accessor.insert(2, 2);
accessor.insert(3, 3);
}
const ConcurrentMap<int, int> &map = input;
auto accessor = map.access();
std::vector<int> results;
for (auto it = accessor.begin(); it != accessor.end(); ++it)
results.push_back(it->first);
EXPECT_THAT(results, testing::ElementsAre(1, 2, 3));
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}