From 542db143edca32c5e8774175c74b2be5c004f20c Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Fri, 27 Mar 2020 14:58:35 +0300 Subject: [PATCH] [search] Add FilterVillages test. --- .../generator_tests_support/test_feature.cpp | 20 ++++ .../generator_tests_support/test_feature.hpp | 12 ++ .../processor_test.cpp | 106 ++++++++++++++++++ 3 files changed, 138 insertions(+) diff --git a/generator/generator_tests_support/test_feature.cpp b/generator/generator_tests_support/test_feature.cpp index 540d898727..6ed96a717b 100644 --- a/generator/generator_tests_support/test_feature.cpp +++ b/generator/generator_tests_support/test_feature.cpp @@ -155,6 +155,26 @@ string TestCountry::ToDebugString() const return os.str(); } +// TestState ------------------------------------------------------------------------------------- +TestState::TestState(m2::PointD const & center, string const & name, string const & lang) + : TestFeature(center, name, lang) +{ +} + +void TestState::Serialize(FeatureBuilder & fb) const +{ + TestFeature::Serialize(fb); + auto const & classificator = classif(); + fb.AddType(classificator.GetTypeByPath({"place", "state"})); +} + +string TestState::ToDebugString() const +{ + ostringstream os; + os << "TestState [" << DebugPrint(m_names) << ", " << DebugPrint(m_center) << "]"; + return os.str(); +} + // TestCity ---------------------------------------------------------------------------------------- TestCity::TestCity(m2::PointD const & center, string const & name, string const & lang, uint8_t rank) diff --git a/generator/generator_tests_support/test_feature.hpp b/generator/generator_tests_support/test_feature.hpp index d7208d71c8..57900b9172 100644 --- a/generator/generator_tests_support/test_feature.hpp +++ b/generator/generator_tests_support/test_feature.hpp @@ -47,6 +47,8 @@ public: return {}; } + m2::PointD const & GetCenter() const { return m_center; } + feature::Metadata & GetMetadata() { return m_metadata; } virtual void Serialize(feature::FeatureBuilder & fb) const; @@ -89,6 +91,16 @@ public: std::string ToDebugString() const override; }; +class TestState : public TestFeature +{ +public: + TestState(m2::PointD const & center, std::string const & name, std::string const & lang); + + // TestFeature overrides: + void Serialize(feature::FeatureBuilder & fb) const override; + std::string ToDebugString() const override; +}; + class TestCity : public TestFeature { public: diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp index 8359ed47c3..d0c79d00e6 100644 --- a/search/search_integration_tests/processor_test.cpp +++ b/search/search_integration_tests/processor_test.cpp @@ -2635,5 +2635,111 @@ UNIT_CLASS_TEST(ProcessorTest, FilterStreetPredictions) TEST(ResultsMatch(request.Results(), rules), ()); } } + +UNIT_CLASS_TEST(ProcessorTest, FilterVillages) +{ + TestState moscowRegion(m2::PointD(10.0, 10.0), "Moscow Region", "en"); + // |moscowRegion| feature shold belong to MoscowRegion with some margin due to mwmPointAccuracy. + TestPOI dummy(m2::PointD(9.99, 9.99), "", "en"); + TestVillage petrovskoeMoscow(m2::PointD(10.5, 10.5), "Petrovskoe", "en", 5 /* rank */); + + TestVillage petrovskoe0(m2::PointD(0.0, 0.0), "Petrovskoe", "en", 5 /* rank */); + TestVillage petrovskoe1(m2::PointD(1.0, 1.0), "Petrovskoe", "en", 5 /* rank */); + TestVillage petrovskoe2(m2::PointD(2.0, 2.0), "Petrovskoe", "en", 5 /* rank */); + + auto const moscowId = BuildCountry("MoscowRegion", [&](TestMwmBuilder & builder) { + builder.Add(petrovskoeMoscow); + builder.Add(dummy); + }); + + auto const otherId = BuildCountry("OtherRegion", [&](TestMwmBuilder & builder) { + builder.Add(petrovskoe0); + builder.Add(petrovskoe1); + builder.Add(petrovskoe2); + }); + + BuildWorld([&](TestMwmBuilder & builder) { builder.Add(moscowRegion); }); + + SearchParams defaultParams; + defaultParams.m_query = "Petrovskoe"; + defaultParams.m_inputLocale = "en"; + defaultParams.m_viewport = m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(1.0, 1.0)); + defaultParams.m_mode = Mode::Everywhere; + defaultParams.m_villageSearchRadiusM = TestSearchRequest::kDefaultTestVillageSearchRadiusM; + + { + Rules const rules = {ExactMatch(otherId, petrovskoe0), ExactMatch(otherId, petrovskoe1), + ExactMatch(otherId, petrovskoe2), ExactMatch(moscowId, petrovskoeMoscow)}; + + TestSearchRequest request(m_engine, defaultParams); + request.Run(); + TEST(ResultsMatch(request.Results(), rules), ()); + } + + { + Rules const rules = {ExactMatch(otherId, petrovskoe0), ExactMatch(otherId, petrovskoe1), + ExactMatch(otherId, petrovskoe2)}; + + auto params = defaultParams; + params.m_villageSearchRadiusM = + mercator::DistanceOnEarth(params.m_viewport.Center(), petrovskoeMoscow.GetCenter()) - 1.0; + + TestSearchRequest request(m_engine, params); + request.Run(); + TEST(ResultsMatch(request.Results(), rules), ()); + } + + { + Rules const rules = {ExactMatch(otherId, petrovskoe0), ExactMatch(otherId, petrovskoe1)}; + + auto params = defaultParams; + params.m_villageSearchRadiusM = + mercator::DistanceOnEarth(params.m_viewport.Center(), petrovskoe2.GetCenter()) - 1.0; + + TestSearchRequest request(m_engine, params); + request.Run(); + TEST(ResultsMatch(request.Results(), rules), ()); + } + + { + Rules const rules = {ExactMatch(otherId, petrovskoe0)}; + + auto params = defaultParams; + params.m_villageSearchRadiusM = + mercator::DistanceOnEarth(params.m_viewport.Center(), petrovskoe1.GetCenter()) - 1.0; + + TestSearchRequest request(m_engine, params); + request.Run(); + TEST(ResultsMatch(request.Results(), rules), ()); + } + + { + Rules const rules = {ExactMatch(otherId, petrovskoe0), ExactMatch(otherId, petrovskoe2)}; + + auto params = defaultParams; + params.m_position = m2::PointD(2.0, 2.0); + params.m_villageSearchRadiusM = + min(mercator::DistanceOnEarth(params.m_viewport.Center(), petrovskoe1.GetCenter()), + mercator::DistanceOnEarth(*params.m_position, petrovskoe1.GetCenter())); + params.m_villageSearchRadiusM -= 1.0; + + TestSearchRequest request(m_engine, params); + request.Run(); + TEST(ResultsMatch(request.Results(), rules), ()); + } + + { + Rules const rules = {ExactMatch(otherId, petrovskoe0), ExactMatch(moscowId, petrovskoeMoscow)}; + + auto params = defaultParams; + params.m_villageSearchRadiusM = + mercator::DistanceOnEarth(params.m_viewport.Center(), petrovskoe1.GetCenter()) - 1.0; + params.m_query = "Petrovskoe Moscow Region"; + + TestSearchRequest request(m_engine, params); + request.Run(); + TEST(ResultsMatch(request.Results(), rules), ()); + } +} } // namespace } // namespace search