Skip to content

Commit d77d875

Browse files
author
Liubov Didkivska
authored
Unit tests for PrefetchRepository. (#728)
* Unit tests for PrefetchRepository. Add tests to check splitting subtree on slices with depth 4. Add tests to calculate subtree with min/max levels default, or specified. Test with sibling tiles on the same levels and different. Resolves:OLPSUP-9847 Signed-off-by: Liubov Didkivska <[email protected]>
1 parent 63c69d5 commit d77d875

File tree

3 files changed

+140
-2
lines changed

3 files changed

+140
-2
lines changed

olp-cpp-sdk-dataservice-read/src/repositories/PrefetchTilesRepository.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using SubQuadsResponse = client::ApiResponse<SubQuadsResult, client::ApiError>;
4444
using SubTilesResult = SubQuadsResult;
4545
using SubTilesResponse = client::ApiResponse<SubTilesResult, client::ApiError>;
4646

47-
class PrefetchTilesRepository final {
47+
class PrefetchTilesRepository {
4848
public:
4949
/**
5050
* @brief Given tile keys, return all related tile keys that are between
@@ -67,7 +67,7 @@ class PrefetchTilesRepository final {
6767
client::CancellationContext context,
6868
const client::OlpClientSettings& settings);
6969

70-
private:
70+
protected:
7171
static SubQuadsResponse GetSubQuads(const client::HRN& catalog,
7272
const std::string& layer_id,
7373
const PrefetchTilesRequest& request,

olp-cpp-sdk-dataservice-read/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(OLP_SDK_DATASERVICE_READ_TEST_SOURCES
2222
DataRepositoryTest.cpp
2323
ParserTest.cpp
2424
PartitionsRepositoryTest.cpp
25+
PrefetchRepositoryTest.cpp
2526
SerializerTest.cpp
2627
StreamApiTest.cpp
2728
StreamLayerClientImplTest.cpp
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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

Comments
 (0)