|
| 1 | +/* |
| 2 | + * Copyright (C) 2020 HERE Europe B.V. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + * License-Filename: LICENSE |
| 18 | + */ |
| 19 | + |
| 20 | +#include <gtest/gtest.h> |
| 21 | + |
| 22 | +#include <repositories/PrefetchTilesRepository.h> |
| 23 | + |
| 24 | +namespace { |
| 25 | +using namespace olp::dataservice::read; |
| 26 | + |
| 27 | +class PrefetchRepositoryTestable |
| 28 | + : protected repository::PrefetchTilesRepository { |
| 29 | + public: |
| 30 | + using repository::PrefetchTilesRepository::GetSlicedTiles; |
| 31 | + using repository::PrefetchTilesRepository::SplitSubtree; |
| 32 | +}; |
| 33 | + |
| 34 | +TEST(PrefetchRepositoryTest, SplitTreeLevel5) { |
| 35 | + repository::RootTilesForRequest root_tiles_depth; |
| 36 | + auto it = |
| 37 | + root_tiles_depth.emplace(olp::geo::TileKey::FromHereTile("5904591"), 5); |
| 38 | + |
| 39 | + PrefetchRepositoryTestable::SplitSubtree(root_tiles_depth, it.first); |
| 40 | + ASSERT_EQ(it.first->second, 0); |
| 41 | + ASSERT_EQ(root_tiles_depth.size(), 1 + pow(4, 1)); |
| 42 | +} |
| 43 | + |
| 44 | +TEST(PrefetchRepositoryTest, SplitTreeLevel8) { |
| 45 | + repository::RootTilesForRequest root_tiles_depth; |
| 46 | + auto it = |
| 47 | + root_tiles_depth.emplace(olp::geo::TileKey::FromHereTile("5904591"), 8); |
| 48 | + |
| 49 | + PrefetchRepositoryTestable::SplitSubtree(root_tiles_depth, it.first); |
| 50 | + ASSERT_EQ(it.first->second, 3); |
| 51 | + ASSERT_EQ(root_tiles_depth.size(), 1 + pow(4, 4)); |
| 52 | +} |
| 53 | + |
| 54 | +TEST(PrefetchRepositoryTest, SplitTreeLevel9) { |
| 55 | + repository::RootTilesForRequest root_tiles_depth; |
| 56 | + auto it = |
| 57 | + root_tiles_depth.emplace(olp::geo::TileKey::FromHereTile("5904591"), 9); |
| 58 | + |
| 59 | + PrefetchRepositoryTestable::SplitSubtree(root_tiles_depth, it.first); |
| 60 | + ASSERT_EQ(it.first->second, 4); |
| 61 | + ASSERT_EQ(root_tiles_depth.size(), 1 + pow(4, 5)); |
| 62 | +} |
| 63 | + |
| 64 | +TEST(PrefetchRepositoryTest, SplitTreeLevel10) { |
| 65 | + repository::RootTilesForRequest root_tiles_depth; |
| 66 | + auto it = |
| 67 | + root_tiles_depth.emplace(olp::geo::TileKey::FromHereTile("5904591"), 10); |
| 68 | + |
| 69 | + PrefetchRepositoryTestable::SplitSubtree(root_tiles_depth, it.first); |
| 70 | + ASSERT_EQ(it.first->second, 0); |
| 71 | + ASSERT_EQ(root_tiles_depth.size(), 1 + pow(4, 1) + pow(4, 6)); |
| 72 | +} |
| 73 | + |
| 74 | +TEST(PrefetchRepositoryTest, GetSlicedTiles) { |
| 75 | + auto tile = olp::geo::TileKey::FromHereTile("5904591"); |
| 76 | + auto root_tiles_depth = |
| 77 | + PrefetchRepositoryTestable::GetSlicedTiles({tile}, 0, 0); |
| 78 | + ASSERT_EQ(root_tiles_depth.size(), 1); |
| 79 | + auto parent = tile.ChangedLevelBy(-4); |
| 80 | + ASSERT_EQ(root_tiles_depth.begin()->first, parent); |
| 81 | + ASSERT_EQ(root_tiles_depth.begin()->second, 4); |
| 82 | +} |
| 83 | + |
| 84 | +TEST(PrefetchRepositoryTest, GetSlicedTilesWithLevelsSpecified) { |
| 85 | + auto tile = olp::geo::TileKey::FromHereTile("5904591"); |
| 86 | + auto root_tiles_depth = |
| 87 | + PrefetchRepositoryTestable::GetSlicedTiles({tile}, 11, 13); |
| 88 | + ASSERT_EQ(root_tiles_depth.begin()->first, tile); |
| 89 | + ASSERT_EQ(root_tiles_depth.begin()->second, 2); |
| 90 | +} |
| 91 | + |
| 92 | +TEST(PrefetchRepositoryTest, GetSlicedTilesWithLevelsSpecified2) { |
| 93 | + auto tile = olp::geo::TileKey::FromHereTile("5904591"); // level 11 |
| 94 | + auto root_tiles_depth = |
| 95 | + PrefetchRepositoryTestable::GetSlicedTiles({tile}, 1, 13); |
| 96 | + auto parent = tile.ChangedLevelBy(-10); |
| 97 | + ASSERT_EQ(root_tiles_depth.find(parent)->second, 2); |
| 98 | + ASSERT_EQ(root_tiles_depth.size(), 1 + pow(4, 3) + pow(4, 8)); |
| 99 | +} |
| 100 | + |
| 101 | +TEST(PrefetchRepositoryTest, GetSlicedTilesDifferentLevelsButLevelsSpecified) { |
| 102 | + auto tile1 = olp::geo::TileKey::FromHereTile("5904591"); // level 11 |
| 103 | + auto tile2 = olp::geo::TileKey::FromHereTile( |
| 104 | + "23618365"); // level 12, this tile will be in the same subtree |
| 105 | + auto root_tiles_depth = |
| 106 | + PrefetchRepositoryTestable::GetSlicedTiles({tile1, tile2}, 1, 13); |
| 107 | + auto parent = tile1.ChangedLevelBy(-10); |
| 108 | + ASSERT_EQ(root_tiles_depth.find(parent)->second, 2); |
| 109 | + ASSERT_EQ(root_tiles_depth.size(), 1 + pow(4, 3) + pow(4, 8)); |
| 110 | +} |
| 111 | + |
| 112 | +TEST(PrefetchRepositoryTest, GetSlicedTilesSibilings) { |
| 113 | + auto tile1 = olp::geo::TileKey::FromHereTile("23618366"); |
| 114 | + auto tile2 = olp::geo::TileKey::FromHereTile("23618365"); |
| 115 | + auto root_tiles_depth = |
| 116 | + PrefetchRepositoryTestable::GetSlicedTiles({tile1, tile2}, 0, 0); |
| 117 | + ASSERT_EQ(root_tiles_depth.size(), 1); |
| 118 | + auto parent1 = tile1.ChangedLevelBy(-4); |
| 119 | + auto parent2 = tile1.ChangedLevelBy(-4); |
| 120 | + ASSERT_EQ(parent1, parent2); |
| 121 | + ASSERT_EQ(root_tiles_depth.begin()->first, parent1); |
| 122 | + ASSERT_EQ(root_tiles_depth.begin()->second, 4); |
| 123 | +} |
| 124 | + |
| 125 | +TEST(PrefetchRepositoryTest, GetSlicedTilesSibilingsWithLevelsSpecified) { |
| 126 | + auto tile1 = olp::geo::TileKey::FromHereTile("23618366"); |
| 127 | + auto tile2 = olp::geo::TileKey::FromHereTile("23618365"); |
| 128 | + auto root_tiles_depth = |
| 129 | + PrefetchRepositoryTestable::GetSlicedTiles({tile1, tile2}, 11, 12); |
| 130 | + ASSERT_EQ(root_tiles_depth.size(), 1); |
| 131 | + auto parent1 = tile1.ChangedLevelBy(-1); |
| 132 | + auto parent2 = tile1.ChangedLevelBy(-1); |
| 133 | + ASSERT_EQ(parent1, parent2); |
| 134 | + ASSERT_EQ(root_tiles_depth.begin()->first, parent1); |
| 135 | + ASSERT_EQ(root_tiles_depth.begin()->second, 1); |
| 136 | +} |
| 137 | +} // namespace |
0 commit comments