From 0c329c16728fc9c149761c381b567870e76e0073 Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 14 Apr 2016 18:04:08 +0300 Subject: [PATCH] [tests] Added POI priority tests. --- map/style_tests/classificator_tests.cpp | 117 +++++++++++++++--------- 1 file changed, 75 insertions(+), 42 deletions(-) diff --git a/map/style_tests/classificator_tests.cpp b/map/style_tests/classificator_tests.cpp index d9d06c4d18..9f88f38897 100644 --- a/map/style_tests/classificator_tests.cpp +++ b/map/style_tests/classificator_tests.cpp @@ -130,7 +130,7 @@ UNIT_TEST(Classificator_DrawingRules) namespace { -pair GetMinMax(int level, vector const & types) +pair GetMinMax(int level, vector const & types, drule::rule_type_t ruleType) { pair res(numeric_limits::max(), numeric_limits::min()); @@ -139,7 +139,7 @@ pair GetMinMax(int level, vector const & types) for (size_t i = 0; i < keys.size(); ++i) { - if (keys[i].m_type != drule::area) + if (keys[i].m_type != ruleType) continue; if (keys[i].m_priority < res.first) @@ -151,6 +151,43 @@ pair GetMinMax(int level, vector const & types) return res; } +void CheckPriority(vector const & arrT, vector const & arrI, drule::rule_type_t ruleType) +{ + Classificator const & c = classif(); + vector > types; + + styles::RunForEveryMapStyle([&](MapStyle) + { + types.clear(); + + size_t ind = 0; + for (size_t i = 0; i < arrI.size(); ++i) + { + types.push_back(vector()); + types.back().reserve(arrI[i]); + + for (size_t j = 0; j < arrI[i]; ++j) + { + types.back().push_back(c.GetTypeByPath(arrT[ind])); + ++ind; + } + } + + TEST_EQUAL(ind, arrT.size(), ()); + + for (int level = scales::GetUpperWorldScale() + 1; level <= scales::GetUpperStyleScale(); ++level) + { + pair minmax(numeric_limits::max(), numeric_limits::min()); + for (size_t i = 0; i < types.size(); ++i) + { + pair const mm = GetMinMax(level, types[i], ruleType); + TEST_LESS(minmax.second, mm.first, (i)); + minmax = mm; + } + } + }); +} + } // namespace // Check area drawing priority according to the types order below (from downmost to upmost). @@ -162,56 +199,52 @@ pair GetMinMax(int level, vector const & types) UNIT_TEST(Classificator_AreaPriority) { - styles::RunForEveryMapStyle([](MapStyle) + vector types = { - Classificator const & c = classif(); + // 0 + {"natural", "coastline"}, + // 1 + //{"waterway", "riverbank"}, - it's not a good idea to place it here + // 2 + {"place", "island"}, {"natural", "land"}, + // 3 + {"natural", "wood"}, {"natural", "scrub"}, {"natural", "heath"}, {"natural", "grassland"}, + {"landuse", "grass"}, {"landuse", "farm"}, {"landuse", "farmland"}, {"landuse", "forest"}, + // 4 + //{"leisure", "park"}, {"leisure", "garden"}, - maybe next time (too tricky to do it now) + // 5 + {"natural", "water"}, {"natural", "lake"}, {"landuse", "basin"} + }; - vector > types; + CheckPriority(types, {1, 2, 8, 3}, drule::area); +} - char const * arrT[][2] = +UNIT_TEST(Classificator_PoiPriority) +{ + { + vector types = { - // 0 - {"natural", "coastline"}, // 1 - //{"waterway", "riverbank"}, - it's not a good idea to place it here + {"amenity", "atm"}, // 2 - {"place", "island"}, {"natural", "land"}, - // 3 - {"natural", "wood"}, {"natural", "scrub"}, {"natural", "heath"}, {"natural", "grassland"}, - {"landuse", "grass"}, {"landuse", "farm"}, {"landuse", "farmland"}, {"landuse", "forest"}, - // 4 - //{"leisure", "park"}, {"leisure", "garden"}, - maybe next time (too tricky to do it now) - // 5 - {"natural", "water"}, {"natural", "lake"}, {"landuse", "basin"} + {"amenity", "bank"} }; - size_t arrI[] = { 1, 2, 8, 3 }; - size_t ind = 0; - for (size_t i = 0; i < ARRAY_SIZE(arrI); ++i) + CheckPriority(types, {1, 1}, drule::symbol); + } + + { + vector types = { - types.push_back(vector()); - types.back().reserve(arrI[i]); + // 1 + {"amenity", "bench"}, {"amenity", "shelter"}, + // 2 + {"highway", "bus_stop"}, {"amenity", "bus_station"}, + {"railway", "station"}, {"railway", "halt"}, {"railway", "tram_stop"}, + }; - for (size_t j = 0; j < arrI[i]; ++j) - { - types.back().push_back(c.GetTypeByPath(vector(arrT[ind], arrT[ind] + 2))); - ++ind; - } - } - - TEST_EQUAL(ind, ARRAY_SIZE(arrT), ()); - - for (int level = scales::GetUpperWorldScale() + 1; level <= scales::GetUpperStyleScale(); ++level) - { - pair minmax = GetMinMax(level, types[0]); - for (size_t i = 1; i < types.size(); ++i) - { - pair const mm = GetMinMax(level, types[i]); - TEST_LESS(minmax.second, mm.first, (i)); - minmax = mm; - } - } - }); + CheckPriority(types, {2, 5}, drule::symbol); + } } UNIT_TEST(Classificator_GetType)