1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
|
#include "catch.hpp"
#include <osmium/index/relations_map.hpp>
#include <type_traits>
static_assert(!std::is_default_constructible<osmium::index::RelationsMapIndex>::value, "RelationsMapIndex should not be default constructible");
static_assert(!std::is_copy_constructible<osmium::index::RelationsMapIndex>::value, "RelationsMapIndex should not be copy constructible");
static_assert(!std::is_copy_constructible<osmium::index::RelationsMapStash>::value, "RelationsMapStash should not be copy constructible");
static_assert(!std::is_copy_assignable<osmium::index::RelationsMapIndex>::value, "RelationsMapIndex should not be copy assignable");
static_assert(!std::is_copy_assignable<osmium::index::RelationsMapStash>::value, "RelationsMapStash should not be copy assignable");
static_assert(std::is_move_constructible<osmium::index::RelationsMapIndex>::value, "RelationsMapIndex should be move constructible");
static_assert(std::is_move_constructible<osmium::index::RelationsMapStash>::value, "RelationsMapStash should be move constructible");
static_assert(std::is_move_assignable<osmium::index::RelationsMapIndex>::value, "RelationsMapIndex should be move assignable");
static_assert(std::is_move_assignable<osmium::index::RelationsMapStash>::value, "RelationsMapStash should be move assignable");
TEST_CASE("RelationsMapStash lvalue") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
REQUIRE(stash.size() == 0); // NOLINT(readability-container-size-empty)
stash.add(1, 2);
stash.add(2, 3);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 2);
const auto sizes = stash.sizes();
REQUIRE(sizes.first == 2);
REQUIRE(sizes.second == 0);
const auto index = stash.build_member_to_parent_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 2);
int count = 0;
index.for_each(1, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 2);
++count;
});
REQUIRE(count == 1);
}
TEST_CASE("RelationsMapStash 64bit") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
REQUIRE(stash.size() == 0); // NOLINT(readability-container-size-empty)
const uint64_t maxsmall = (1ULL << 32ULL) - 1;
const uint64_t large = 1ULL << 33ULL;
stash.add(1, 2);
stash.add(2, maxsmall);
stash.add(3, large + 1);
stash.add(4, large + 2);
stash.add(5, large + 3);
stash.add(large + 5, 5);
stash.add(large + 6, 6);
stash.add(large + 7, large + 8);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 8);
const auto sizes = stash.sizes();
REQUIRE(sizes.first == 2);
REQUIRE(sizes.second == 6);
const auto index = stash.build_member_to_parent_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 8);
int count = 0;
index.for_each(1, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 2);
++count;
});
index.for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == maxsmall);
++count;
});
index.for_each(3, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == large + 1);
++count;
});
index.for_each(4, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == large + 2);
++count;
});
index.for_each(5, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == large + 3);
++count;
});
index.for_each(large + 5, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 5);
++count;
});
index.for_each(large + 6, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 6);
++count;
});
index.for_each(large + 7, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == large + 8);
++count;
});
REQUIRE(count == 8);
}
TEST_CASE("RelationsMapStash duplicates will be removed in index") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
const uint64_t large = 1ULL << 33ULL;
stash.add(1, 2);
stash.add(2, 3);
stash.add(1, 2); // duplicate
stash.add(2, 2);
stash.add(1, 2); // another duplicate
stash.add(5, large + 1);
stash.add(5, 4);
stash.add(5, large + 1); // also duplicate
stash.add(large + 2, 1);
stash.add(large + 2, 4);
stash.add(large + 2, 1); // also duplicate
REQUIRE(stash.size() == 11);
const auto sizes = stash.sizes();
REQUIRE(sizes.first == 6);
REQUIRE(sizes.second == 5);
SECTION("member to parent") {
const auto index = stash.build_member_to_parent_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 7);
}
SECTION("parent to member") {
const auto index = stash.build_parent_to_member_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 7);
}
}
TEST_CASE("RelationsMapStash n:m results") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
const uint64_t large = 1ULL << 33ULL;
stash.add(3, large + 1);
stash.add(3, large + 2);
stash.add(4, large + 1);
stash.add(4, large + 2);
stash.add(4, large + 1);
stash.add(5, large + 2);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 6);
const auto sizes = stash.sizes();
REQUIRE(sizes.first == 0);
REQUIRE(sizes.second == 6);
const auto index = stash.build_member_to_parent_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 5);
int count = 0;
index.for_each(2, [&](osmium::unsigned_object_id_type /*id*/) {
REQUIRE(false);
});
index.for_each(3, [&](osmium::unsigned_object_id_type id) {
REQUIRE(((id == large + 1) || (id == large + 2)));
++count;
});
index.for_each(4, [&](osmium::unsigned_object_id_type id) {
REQUIRE(((id == large + 1) || (id == large + 2)));
++count;
});
index.for_each(5, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == large + 2);
++count;
});
REQUIRE(count == 5);
}
namespace {
osmium::index::RelationsMapIndex func() {
osmium::index::RelationsMapStash stash;
stash.add(1, 2);
stash.add(2, 3);
return stash.build_member_to_parent_index();
}
} // anonymous namespace
TEST_CASE("RelationsMapStash rvalue") {
const osmium::index::RelationsMapIndex index{func()};
int count = 0;
index.for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 3);
++count;
});
REQUIRE(count == 1);
}
TEST_CASE("RelationsMapStash reverse index") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
stash.add(1, 2);
stash.add(2, 3);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 2);
const auto index = stash.build_parent_to_member_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 2);
int count = 0;
index.for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 1);
++count;
});
index.for_each(3, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 2);
++count;
});
REQUIRE(count == 2);
}
TEST_CASE("RelationsMapStash reverse index with 64bit values") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
const uint64_t large = 1ULL << 33ULL;
stash.add(1, 2);
stash.add(2, 3);
stash.add(3, large + 1);
stash.add(4, large + 2);
stash.add(5, large + 3);
stash.add(large + 5, 5);
stash.add(large + 6, 6);
stash.add(large + 7, large + 8);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 8);
const auto sizes = stash.sizes();
REQUIRE(sizes.first == 2);
REQUIRE(sizes.second == 6);
const auto index = stash.build_parent_to_member_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 8);
int count = 0;
index.for_each(1, [&](osmium::unsigned_object_id_type /*id*/) {
REQUIRE(false);
});
index.for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 1);
++count;
});
index.for_each(3, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 2);
++count;
});
index.for_each(large + 1, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 3);
++count;
});
index.for_each(large + 2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 4);
++count;
});
index.for_each(large + 3, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 5);
++count;
});
index.for_each(5, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == large + 5);
++count;
});
index.for_each(6, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == large + 6);
++count;
});
index.for_each(large + 8, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == large + 7);
++count;
});
REQUIRE(count == 8);
}
TEST_CASE("RelationsMapStash both indexes") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
stash.add(1, 2);
stash.add(2, 3);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 2);
const auto indexes = stash.build_indexes();
REQUIRE_FALSE(indexes.empty());
REQUIRE(indexes.size() == 2);
int count = 0;
indexes.member_to_parent().for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 3);
++count;
});
indexes.parent_to_member().for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 1);
++count;
});
REQUIRE(count == 2);
}
TEST_CASE("RelationsMapStash small and large") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
stash.add(1, 2);
stash.add(2, 3);
stash.add(4, (1ULL << 32ULL) - 1);
stash.add((1ULL << 32ULL) - 1, 5);
REQUIRE(stash.sizes().first == 4);
REQUIRE(stash.sizes().second == 0);
stash.add(6, (1ULL << 32ULL) + 1);
stash.add((1ULL << 32ULL) + 1, 7);
REQUIRE(stash.sizes().first == 4);
REQUIRE(stash.sizes().second == 2);
stash.add(8, (1ULL << 63ULL));
stash.add((1ULL << 63ULL), 9);
REQUIRE(stash.sizes().first == 4);
REQUIRE(stash.sizes().second == 4);
}
|