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 +#include +#include + +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 const & types, size_t expectedCount) { + vector 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 diff --git a/xcode/search/search.xcodeproj/project.pbxproj b/xcode/search/search.xcodeproj/project.pbxproj index ce60485e3c..cd1038d785 100644 --- a/xcode/search/search.xcodeproj/project.pbxproj +++ b/xcode/search/search.xcodeproj/project.pbxproj @@ -163,6 +163,7 @@ 3D0AEB021FBB102C00AD042B /* libgenerator_tests_support.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D0AEB041FBB102C00AD042B /* libgenerator_tests_support.a */; }; 3DA5722B20C1956D007BDE27 /* integration_tests_helpers.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3DA5722920C1956D007BDE27 /* integration_tests_helpers.hpp */; }; 3DFEBF761EF2D55800317D5C /* city_finder.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3DFEBF751EF2D55800317D5C /* city_finder.hpp */; }; + 405DB10720FF472300EE3824 /* utils_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 405DB10620FF472300EE3824 /* utils_test.cpp */; }; 453C623B2004BABE00467120 /* region_info_getter.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 453C62392004BABE00467120 /* region_info_getter.hpp */; }; 453C623C2004BABE00467120 /* region_info_getter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 453C623A2004BABE00467120 /* region_info_getter.cpp */; }; 456E1B3E1F9A3C8E009C32E1 /* cities_boundaries_table.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 456E1B3C1F9A3C8D009C32E1 /* cities_boundaries_table.cpp */; }; @@ -424,6 +425,7 @@ 3DA5722820C1956D007BDE27 /* integration_tests_helpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = integration_tests_helpers.cpp; sourceTree = ""; }; 3DA5722920C1956D007BDE27 /* integration_tests_helpers.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = integration_tests_helpers.hpp; sourceTree = ""; }; 3DFEBF751EF2D55800317D5C /* city_finder.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = city_finder.hpp; sourceTree = ""; }; + 405DB10620FF472300EE3824 /* utils_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = utils_test.cpp; sourceTree = ""; }; 453C62392004BABE00467120 /* region_info_getter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = region_info_getter.hpp; sourceTree = ""; }; 453C623A2004BABE00467120 /* region_info_getter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = region_info_getter.cpp; sourceTree = ""; }; 456E1B3C1F9A3C8D009C32E1 /* cities_boundaries_table.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cities_boundaries_table.cpp; sourceTree = ""; }; @@ -700,6 +702,7 @@ 39B387691FB4609700964D61 /* search_integration_tests */ = { isa = PBXGroup; children = ( + 405DB10620FF472300EE3824 /* utils_test.cpp */, 39B2B94E1FB4620800AB85A1 /* smoke_test.cpp */, 39B2B94D1FB4620800AB85A1 /* tracer_tests.cpp */, 39B2B9451FB4620200AB85A1 /* pre_ranker_test.cpp */, @@ -1243,6 +1246,7 @@ 39831A3820F3C5C6005FF294 /* merger.cpp in Sources */, F652D8BF1CFDE1E800FC29A0 /* engine.cpp in Sources */, 675346DD1A40560D00A0A8C3 /* approximate_string_match.cpp in Sources */, + 405DB10720FF472300EE3824 /* utils_test.cpp in Sources */, 34586B8B1DCB1E8300CF7FC9 /* interval_set_test.cpp in Sources */, 0810EC361D6D9D2E00ABFEE7 /* displayed_categories.cpp in Sources */, 675346E51A40560D00A0A8C3 /* intermediate_result.cpp in Sources */,