diff options
author | Sergey Yershov <yershov@corp.mail.ru> | 2016-04-25 20:11:59 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-04-26 12:18:50 +0300 |
commit | d22f657bdbad7d65bcf6c08052033e286bd93fef (patch) | |
tree | 0d02ccf1ceeb683f4894ad1b30934e464970ab14 /storage | |
parent | c48d034f8b6e2c235a2dbd62357cddd317106b2c (diff) |
[downloader] Fix GetTopmostNodesFor and added test
Diffstat (limited to 'storage')
-rw-r--r-- | storage/storage.cpp | 11 | ||||
-rw-r--r-- | storage/storage.hpp | 3 | ||||
-rw-r--r-- | storage/storage_tests/storage_tests.cpp | 21 |
3 files changed, 28 insertions, 7 deletions
diff --git a/storage/storage.cpp b/storage/storage.cpp index c54020b8ad..5c8e7baafc 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -1642,15 +1642,14 @@ void Storage::GetTopmostNodesFor(TCountryId const & countryId, TCountriesVec & n return; } - nodes.clear(); nodes.resize(treeNodes.size()); - for (auto & node : nodes) + for (size_t i = 0; i < treeNodes.size(); ++i) { - node = countryId; - ForEachAncestorExceptForTheRoot(treeNodes, - [&node](TCountryId const & id, TCountryTreeNode const &) + nodes[i] = countryId; + ForEachAncestorExceptForTheRoot({treeNodes[i]}, + [&nodes, i](TCountryId const & id, TCountryTreeNode const &) { - node = id; + nodes[i] = id; }); } } diff --git a/storage/storage.hpp b/storage/storage.hpp index 53bf3fb3ec..f18c78e471 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -355,7 +355,8 @@ public: /// \param path is resulting array of TCountryId. void GetGroupNodePathToRoot(TCountryId const & groupNode, TCountriesVec & path) const; - /// \brief TODO + /// \brief Fills |nodes| with CountryIds of topmost nodes for this |countryId|. + /// For disputed territories all possible owners will be added. void GetTopmostNodesFor(TCountryId const & countryId, TCountriesVec & nodes) const; /// \brief Returns current version for mwms which are used by storage. diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index 2fc2a610e9..4073a3fea3 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -1674,4 +1674,25 @@ UNIT_TEST(StorageTest_GetGroupNodePathToRootTest) storage.GetGroupNodePathToRoot("Country1", path); TEST(path.empty(), ()); } + +UNIT_TEST(StorageTest_GetTopmostNodesFor) +{ + Storage storage; + + TCountriesVec path; + + storage.GetTopmostNodesFor("France_Auvergne_Allier", path); + TEST_EQUAL(path.size(), 1, (path)); + TEST_EQUAL(path[0], "France", ()); + + storage.GetTopmostNodesFor("France_Auvergne", path); + TEST_EQUAL(path.size(), 1, (path)); + TEST_EQUAL(path[0], "France", ()); + + storage.GetTopmostNodesFor("Jerusalem", path); + TEST_EQUAL(path.size(), 2, (path)); + TEST_EQUAL(path[0], "Israel Region", (path)); + TEST_EQUAL(path[1], "Palestine Region", (path)); +} + } // namespace storage |