diff options
author | tatiana-yan <tatiana.kondakova@gmail.com> | 2018-10-15 12:36:50 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <bykoianko@gmail.com> | 2018-10-16 15:03:27 +0300 |
commit | e5cc7611b02f38e0183aa14f7048934c69e12153 (patch) | |
tree | 854d64af0bae3c5b73cf39c9009737842b8f3b2d /indexer | |
parent | 5988550ca97829794629921fa7df200237710b1e (diff) |
[indexer] Add classificator tests.
Diffstat (limited to 'indexer')
-rw-r--r-- | indexer/indexer_tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | indexer/indexer_tests/classificator_tests.cpp | 96 |
2 files changed, 97 insertions, 0 deletions
diff --git a/indexer/indexer_tests/CMakeLists.txt b/indexer/indexer_tests/CMakeLists.txt index 650b64dc7a..e103677009 100644 --- a/indexer/indexer_tests/CMakeLists.txt +++ b/indexer/indexer_tests/CMakeLists.txt @@ -10,6 +10,7 @@ set( centers_table_test.cpp checker_test.cpp cities_boundaries_serdes_tests.cpp + classificator_tests.cpp data_source_test.cpp drules_selector_parser_test.cpp editable_map_object_test.cpp diff --git a/indexer/indexer_tests/classificator_tests.cpp b/indexer/indexer_tests/classificator_tests.cpp new file mode 100644 index 0000000000..325b1e5aff --- /dev/null +++ b/indexer/indexer_tests/classificator_tests.cpp @@ -0,0 +1,96 @@ +#include "testing/testing.hpp" + +#include "indexer/classificator.hpp" +#include "indexer/classificator_loader.hpp" + +#include <algorithm> +#include <cstdint> +#include <string> +#include <vector> + +using namespace std; + +namespace +{ +class ClassificatorTest +{ +public: + ClassificatorTest() + { + classificator::Load(); + } + + ~ClassificatorTest() = default; +}; +} // namespace + +UNIT_CLASS_TEST(ClassificatorTest, Classificator_GetType) +{ + Classificator const & c = classif(); + + uint32_t const type1 = c.GetTypeByPath({"natural", "coastline"}); + TEST_NOT_EQUAL(0, type1, ()); + TEST(c.IsTypeValid(type1), ()); + TEST_EQUAL(type1, c.GetTypeByReadableObjectName("natural-coastline"), ()); + + uint32_t const type2 = c.GetTypeByPath({"amenity", "parking", "private"}); + TEST_NOT_EQUAL(0, type2, ()); + TEST(c.IsTypeValid(type2), ()); + TEST_EQUAL(type2, c.GetTypeByReadableObjectName("amenity-parking-private"), ()); + + TEST_EQUAL(0, c.GetTypeByPathSafe({"nonexisting", "type"}), ()); + TEST_EQUAL(0, c.GetTypeByReadableObjectName("nonexisting-type"), ()); + TEST(!c.IsTypeValid(0), ()); +} + +UNIT_CLASS_TEST(ClassificatorTest, Classificator_CoastlineType) +{ + Classificator const & c = classif(); + + uint32_t const type = c.GetTypeByPath({"natural", "coastline"}); + TEST(c.IsTypeValid(type), ()); + TEST_EQUAL(type, c.GetCoastType(), ()); +} + +UNIT_CLASS_TEST(ClassificatorTest, Classificator_GetIndex) +{ + Classificator const & c = classif(); + + uint32_t const type = c.GetTypeByPath({"railway", "station", "subway"}); + uint32_t const index = c.GetIndexForType(type); + TEST(c.IsTypeValid(type), ()); + TEST_EQUAL(type, c.GetTypeForIndex(index), ()); +} + +UNIT_CLASS_TEST(ClassificatorTest, Classificator_Subtree) +{ + Classificator const & c = classif(); + + uint32_t const cityType = c.GetTypeByPath({"place", "city"}); + + vector<vector<string>> const expectedPaths = { + {"place", "city"}, + {"place", "city", "capital"}, + {"place", "city", "capital", "2"}, + {"place", "city", "capital", "3"}, + {"place", "city", "capital", "4"}, + {"place", "city", "capital", "5"}, + {"place", "city", "capital", "6"}, + {"place", "city", "capital", "7"}, + {"place", "city", "capital", "8"}, + {"place", "city", "capital", "9"}, + {"place", "city", "capital", "10"}, + {"place", "city", "capital", "11"}, + }; + + vector<uint32_t> expectedTypes; + for (auto const & path : expectedPaths) + expectedTypes.push_back(classif().GetTypeByPath(path)); + sort(expectedTypes.begin(), expectedTypes.end()); + + vector<uint32_t> subtreeTypes; + c.ForEachInSubtree([&subtreeTypes](uint32_t type) { subtreeTypes.push_back(type); }, cityType); + sort(subtreeTypes.begin(), subtreeTypes.end()); + + TEST_EQUAL(expectedTypes, subtreeTypes, ()); +} |