diff options
author | tatiana-yan <tatiana.kondakova@gmail.com> | 2018-07-18 13:06:50 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2018-07-18 15:11:04 +0300 |
commit | 46d5cd803a7896260387dc0201ef0240888e0ca9 (patch) | |
tree | b8099a36333e20367b42dba606224c26c808418f /search | |
parent | ec70731d835e820af520ad489a9ecd88d78b49d3 (diff) |
[search] Add test for Discovery helpers
Diffstat (limited to 'search')
-rw-r--r-- | search/search_integration_tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | search/search_integration_tests/utils_test.cpp | 99 |
2 files changed, 100 insertions, 0 deletions
diff --git a/search/search_integration_tests/CMakeLists.txt b/search/search_integration_tests/CMakeLists.txt index 3f0c644b09..2051defd6c 100644 --- a/search/search_integration_tests/CMakeLists.txt +++ b/search/search_integration_tests/CMakeLists.txt @@ -10,6 +10,7 @@ set( search_edited_features_test.cpp smoke_test.cpp tracer_tests.cpp + utils_test.cpp ) omim_add_test(${PROJECT_NAME} ${SRC}) diff --git a/search/search_integration_tests/utils_test.cpp b/search/search_integration_tests/utils_test.cpp new file mode 100644 index 0000000000..0173c5f88e --- /dev/null +++ b/search/search_integration_tests/utils_test.cpp @@ -0,0 +1,99 @@ +#include "testing/testing.hpp" + +#include "search/search_tests_support/helpers.hpp" + +#include "generator/feature_builder.hpp" +#include "generator/generator_tests_support/test_feature.hpp" +#include "generator/generator_tests_support/test_mwm_builder.hpp" + +#include "indexer/categories_holder.hpp" +#include "indexer/classificator.hpp" +#include "indexer/feature_decl.hpp" + +#include "geometry/point2d.hpp" +#include "geometry/rect2d.hpp" + +#include <algorithm> +#include <string> +#include <vector> + +using namespace generator::tests_support; +using namespace search::tests_support; +using namespace std; + +namespace search +{ +namespace +{ +class SearchUtilsTest : public SearchTest +{ +public: + DataSource const & GetDataSource() const { return m_dataSource; } +}; + +UNIT_CLASS_TEST(SearchUtilsTest, Utils) +{ + string const kCountryName = "FoodLand"; + auto file = platform::LocalCountryFile::MakeForTesting(kCountryName); + + TestPOI cafe(m2::PointD(0.0, 0.0), "cafe", "en"); + cafe.SetTypes({{"amenity", "cafe"}}); + + TestPOI restaurant(m2::PointD(0.0, 0.0), "restaurant", "en"); + restaurant.SetTypes({{"amenity", "restaurant"}}); + + TestPOI bar(m2::PointD(0.0, 0.0), "bar", "en"); + bar.SetTypes({{"amenity", "bar"}}); + + auto id = BuildCountry(kCountryName, [&](TestMwmBuilder & builder) { + builder.Add(cafe); + builder.Add(restaurant); + builder.Add(bar); + }); + + auto const & categories = GetDefaultCategories(); + auto const typesCafe = GetCategoryTypes("Cafe", "en", categories); + auto const typesRestaurant = GetCategoryTypes("Restaurant", "en", categories); + auto const typesBar = GetCategoryTypes("Bar", "en", categories); + auto const typesFood = GetCategoryTypes("Food", "en", categories); + + // GetCategoryTypes must return sorted vector of types. + TEST(is_sorted(typesCafe.begin(), typesCafe.end()), ()); + TEST(is_sorted(typesRestaurant.begin(), typesRestaurant.end()), ()); + TEST(is_sorted(typesBar.begin(), typesBar.end()), ()); + TEST(is_sorted(typesFood.begin(), typesFood.end()), ()); + + // Now "Cafe" and "Restaurant" are synonyms in categories. + TEST_EQUAL(typesCafe, typesRestaurant, ()); + TEST_NOT_EQUAL(typesCafe, typesBar, ()); + + for (auto const t : typesCafe) + TEST(binary_search(typesFood.begin(), typesFood.end(), t), ()); + + for (auto const t : typesBar) + TEST(binary_search(typesFood.begin(), typesFood.end(), t), ()); + + auto const & dataSource = GetDataSource(); + auto const rect = m2::RectD(m2::PointD(-0.5, -0.5), m2::PointD(0.5, 0.5)); + + auto const testTypes = [&](vector<uint32_t> const & types, size_t expectedCount) { + vector<FeatureID> features; + ForEachOfTypesInRect(dataSource, types, rect, + [&features](FeatureID const & f) { features.push_back(f); }); + TEST_EQUAL(features.size(), expectedCount, ()); + }; + + // |cafe| and |restaurant|. + testTypes(typesCafe, 2); + + // |cafe| and |restaurant|. + testTypes(typesRestaurant, 2); + + // |bar|. + testTypes(typesBar, 1); + + // All. + testTypes(typesFood, 3); +} +} // namespace +} // namespace search |