forked from organicmaps/organicmaps-tmp
[search] Simplified search integration tests.
This commit is contained in:
parent
023441f859
commit
e4bbd37deb
4 changed files with 70 additions and 66 deletions
|
@ -34,6 +34,8 @@
|
|||
|
||||
using namespace search::tests_support;
|
||||
|
||||
using TRules = vector<shared_ptr<MatchingRule>>;
|
||||
|
||||
namespace
|
||||
{
|
||||
void InitParams(string const & query, search::SearchQueryParams & params)
|
||||
|
@ -142,9 +144,9 @@ UNIT_TEST(Retrieval_Smoke)
|
|||
platform::LocalCountryFile file(platform.WritableDir(), platform::CountryFile("WhiskeyTown"), 0);
|
||||
Cleanup(file);
|
||||
MY_SCOPE_GUARD(deleteFile, [&]()
|
||||
{
|
||||
Cleanup(file);
|
||||
});
|
||||
{
|
||||
Cleanup(file);
|
||||
});
|
||||
|
||||
// Create a test mwm with 100 whiskey bars.
|
||||
{
|
||||
|
@ -228,9 +230,9 @@ UNIT_TEST(Retrieval_3Mwms)
|
|||
platform::LocalCountryFile zrh(platform.WritableDir(), platform::CountryFile("zrh"), 0);
|
||||
Cleanup({msk, mtv, zrh});
|
||||
MY_SCOPE_GUARD(cleanup, [&]()
|
||||
{
|
||||
Cleanup({msk, mtv, zrh});
|
||||
});
|
||||
{
|
||||
Cleanup({msk, mtv, zrh});
|
||||
});
|
||||
|
||||
{
|
||||
TestMwmBuilder builder(msk, feature::DataHeader::country);
|
||||
|
@ -339,7 +341,7 @@ UNIT_TEST(Retrieval_CafeMTV)
|
|||
0);
|
||||
Cleanup({msk, mtv, testWorld});
|
||||
MY_SCOPE_GUARD(cleanup, [&]()
|
||||
{
|
||||
{
|
||||
Cleanup({msk, mtv, testWorld});
|
||||
});
|
||||
|
||||
|
@ -387,10 +389,8 @@ UNIT_TEST(Retrieval_CafeMTV)
|
|||
TestSearchRequest request(engine, "Moscow ", "en", search::Mode::Everywhere, mskViewport);
|
||||
request.Wait();
|
||||
|
||||
initializer_list<shared_ptr<MatchingRule>> mskCityAlts = {
|
||||
make_shared<ExactMatch>(testWorldId, mskCity), make_shared<ExactMatch>(mskId, mskCity)};
|
||||
vector<shared_ptr<MatchingRule>> rules = {make_shared<AlternativesMatch>(mskCityAlts),
|
||||
make_shared<ExactMatch>(mtvId, mskCafe)};
|
||||
auto mskCityAlts = {ExactMatch(testWorldId, mskCity), ExactMatch(mskId, mskCity)};
|
||||
TRules rules = {AlternativesMatch(mskCityAlts), ExactMatch(mtvId, mskCafe)};
|
||||
TEST(MatchResults(engine, rules, request.Results()), ());
|
||||
}
|
||||
|
||||
|
@ -398,10 +398,8 @@ UNIT_TEST(Retrieval_CafeMTV)
|
|||
TestSearchRequest request(engine, "MTV ", "en", search::Mode::Everywhere, mtvViewport);
|
||||
request.Wait();
|
||||
|
||||
initializer_list<shared_ptr<MatchingRule>> mtvCityAlts = {
|
||||
make_shared<ExactMatch>(testWorldId, mtvCity), make_shared<ExactMatch>(mtvId, mtvCity)};
|
||||
vector<shared_ptr<MatchingRule>> rules = {make_shared<AlternativesMatch>(mtvCityAlts),
|
||||
make_shared<ExactMatch>(mskId, mtvCafe)};
|
||||
auto mtvCityAlts = {ExactMatch(testWorldId, mtvCity), ExactMatch(mtvId, mtvCity)};
|
||||
TRules rules = {AlternativesMatch(mtvCityAlts), ExactMatch(mskId, mtvCafe)};
|
||||
TEST(MatchResults(engine, rules, request.Results()), ());
|
||||
}
|
||||
|
||||
|
@ -409,9 +407,8 @@ UNIT_TEST(Retrieval_CafeMTV)
|
|||
TestSearchRequest request(engine, "Moscow MTV ", "en", search::Mode::Everywhere, mtvViewport);
|
||||
request.Wait();
|
||||
|
||||
initializer_list<shared_ptr<MatchingRule>> alternatives = {
|
||||
make_shared<ExactMatch>(mskId, mtvCafe), make_shared<ExactMatch>(mtvId, mskCafe)};
|
||||
vector<shared_ptr<MatchingRule>> rules = {make_shared<AlternativesMatch>(alternatives)};
|
||||
auto alternatives = {ExactMatch(mskId, mtvCafe), ExactMatch(mtvId, mskCafe)};
|
||||
TRules rules = {AlternativesMatch(alternatives)};
|
||||
|
||||
// TODO (@gorshenin): current search algorithm can't retrieve both
|
||||
// Cafe Moscow @ MTV and Cafe MTV @ Moscow, it'll just return one
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
void RegisterCountry(string const & name, m2::RectD const & rect)
|
||||
{
|
||||
auto & infoGetter =
|
||||
static_cast<storage::CountryInfoGetterForTesting&>(m_engine.GetCountryInfoGetter());
|
||||
static_cast<storage::CountryInfoGetterForTesting &>(m_engine.GetCountryInfoGetter());
|
||||
infoGetter.AddCountry(storage::CountryDef(name, rect));
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,8 @@ public:
|
|||
return MatchResults(m_engine, rules, request.Results());
|
||||
}
|
||||
|
||||
bool ResultsMatch(string const & query, search::Mode mode, vector<shared_ptr<MatchingRule>> const & rules)
|
||||
bool ResultsMatch(string const & query, search::Mode mode,
|
||||
vector<shared_ptr<MatchingRule>> const & rules)
|
||||
{
|
||||
TestSearchRequest request(m_engine, query, "en", mode, m_viewport);
|
||||
request.Wait();
|
||||
|
@ -204,69 +205,65 @@ UNIT_CLASS_TEST(SearchQueryV2Test, Smoke)
|
|||
SetViewport(m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(1.0, 1.0)));
|
||||
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, busStop)};
|
||||
TRules rules = {ExactMatch(wonderlandId, busStop)};
|
||||
TEST(ResultsMatch("Bus stop", rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, quantumCafe),
|
||||
make_shared<ExactMatch>(wonderlandId, quantumTeleport1),
|
||||
make_shared<ExactMatch>(wonderlandId, quantumTeleport2)};
|
||||
TRules rules = {ExactMatch(wonderlandId, quantumCafe),
|
||||
ExactMatch(wonderlandId, quantumTeleport1),
|
||||
ExactMatch(wonderlandId, quantumTeleport2)};
|
||||
TEST(ResultsMatch("quantum", rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, quantumCafe),
|
||||
make_shared<ExactMatch>(wonderlandId, quantumTeleport1)};
|
||||
TRules rules = {ExactMatch(wonderlandId, quantumCafe),
|
||||
ExactMatch(wonderlandId, quantumTeleport1)};
|
||||
TEST(ResultsMatch("quantum Moscow ", rules), ());
|
||||
}
|
||||
{
|
||||
TEST(ResultsMatch(" ", TRules()), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, quantumTeleport2)};
|
||||
TRules rules = {ExactMatch(wonderlandId, quantumTeleport2)};
|
||||
TEST(ResultsMatch("teleport feynman street", rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, quantumTeleport2)};
|
||||
TRules rules = {ExactMatch(wonderlandId, quantumTeleport2)};
|
||||
TEST(ResultsMatch("feynman street 3", rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, feynmanHouse),
|
||||
make_shared<ExactMatch>(wonderlandId, lantern1)};
|
||||
TRules rules = {ExactMatch(wonderlandId, feynmanHouse), ExactMatch(wonderlandId, lantern1)};
|
||||
TEST(ResultsMatch("feynman street 1", rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, bohrHouse),
|
||||
make_shared<ExactMatch>(wonderlandId, hilbertHouse),
|
||||
make_shared<ExactMatch>(wonderlandId, lantern1)};
|
||||
TRules rules = {ExactMatch(wonderlandId, bohrHouse), ExactMatch(wonderlandId, hilbertHouse),
|
||||
ExactMatch(wonderlandId, lantern1)};
|
||||
TEST(ResultsMatch("bohr street 1", rules), ());
|
||||
}
|
||||
{
|
||||
TEST(ResultsMatch("bohr street 1 unit 3", TRules()), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, lantern1),
|
||||
make_shared<ExactMatch>(wonderlandId, lantern2)};
|
||||
TRules rules = {ExactMatch(wonderlandId, lantern1), ExactMatch(wonderlandId, lantern2)};
|
||||
TEST(ResultsMatch("bohr street 1 lantern ", rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, feynmanHouse)};
|
||||
TRules rules = {ExactMatch(wonderlandId, feynmanHouse)};
|
||||
TEST(ResultsMatch("wonderland los alamos feynman 1 unit 1 ", rules), ());
|
||||
}
|
||||
{
|
||||
// It's possible to find Descartes house by name.
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, descartesHouse)};
|
||||
TRules rules = {ExactMatch(wonderlandId, descartesHouse)};
|
||||
TEST(ResultsMatch("Los Alamos Descartes", rules), ());
|
||||
}
|
||||
{
|
||||
// It's not possible to find Descartes house by house number,
|
||||
// because it doesn't belong to Los Alamos streets. But it still
|
||||
// exists.
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, lantern2),
|
||||
make_shared<ExactMatch>(wonderlandId, quantumTeleport2)};
|
||||
TRules rules = {ExactMatch(wonderlandId, lantern2), ExactMatch(wonderlandId, quantumTeleport2)};
|
||||
TEST(ResultsMatch("Los Alamos 2", rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, bornHouse)};
|
||||
TRules rules = {ExactMatch(wonderlandId, bornHouse)};
|
||||
TEST(ResultsMatch("long pond 1st april street 8", rules), ());
|
||||
}
|
||||
}
|
||||
|
@ -276,8 +273,7 @@ UNIT_CLASS_TEST(SearchQueryV2Test, SearchInWorld)
|
|||
TestCountry wonderland(m2::PointD(0, 0), "Wonderland", "en");
|
||||
TestCity losAlamos(m2::PointD(0, 0), "Los Alamos", "en", 100 /* rank */);
|
||||
|
||||
auto testWorldId = BuildMwm("testWorld", feature::DataHeader::world,
|
||||
[&](TestMwmBuilder & builder)
|
||||
auto testWorldId = BuildMwm("testWorld", feature::DataHeader::world, [&](TestMwmBuilder & builder)
|
||||
{
|
||||
builder.Add(wonderland);
|
||||
builder.Add(losAlamos);
|
||||
|
@ -287,15 +283,15 @@ UNIT_CLASS_TEST(SearchQueryV2Test, SearchInWorld)
|
|||
|
||||
SetViewport(m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(-0.5, -0.5)));
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(testWorldId, losAlamos)};
|
||||
TRules rules = {ExactMatch(testWorldId, losAlamos)};
|
||||
TEST(ResultsMatch("Los Alamos", rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(testWorldId, wonderland)};
|
||||
TRules rules = {ExactMatch(testWorldId, wonderland)};
|
||||
TEST(ResultsMatch("Wonderland", rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(testWorldId, losAlamos)};
|
||||
TRules rules = {ExactMatch(testWorldId, losAlamos)};
|
||||
TEST(ResultsMatch("Wonderland Los Alamos", rules), ());
|
||||
}
|
||||
}
|
||||
|
@ -312,18 +308,18 @@ UNIT_CLASS_TEST(SearchQueryV2Test, SearchByName)
|
|||
{
|
||||
builder.Add(london);
|
||||
});
|
||||
auto wonderlandId = BuildMwm("wonderland", feature::DataHeader::country,
|
||||
[&](TestMwmBuilder & builder)
|
||||
{
|
||||
builder.Add(hydePark);
|
||||
builder.Add(cafe);
|
||||
});
|
||||
auto wonderlandId =
|
||||
BuildMwm("wonderland", feature::DataHeader::country, [&](TestMwmBuilder & builder)
|
||||
{
|
||||
builder.Add(hydePark);
|
||||
builder.Add(cafe);
|
||||
});
|
||||
RegisterCountry("Wonderland", m2::RectD(m2::PointD(0, 0), m2::PointD(2, 2)));
|
||||
|
||||
SetViewport(m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(-0.9, -0.9)));
|
||||
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, hydePark)};
|
||||
TRules rules = {ExactMatch(wonderlandId, hydePark)};
|
||||
TEST(ResultsMatch("hyde park", rules), ());
|
||||
TEST(ResultsMatch("london hyde park", rules), ());
|
||||
TEST(ResultsMatch("hyde london park", TRules()), ());
|
||||
|
@ -331,12 +327,11 @@ UNIT_CLASS_TEST(SearchQueryV2Test, SearchByName)
|
|||
|
||||
SetViewport(m2::RectD(m2::PointD(0.5, 0.5), m2::PointD(1.5, 1.5)));
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(worldId, london)};
|
||||
TRules rules = {ExactMatch(worldId, london)};
|
||||
TEST(ResultsMatch("london", search::Mode::World, rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(worldId, london),
|
||||
make_shared<ExactMatch>(wonderlandId, cafe)};
|
||||
TRules rules = {ExactMatch(worldId, london), ExactMatch(wonderlandId, cafe)};
|
||||
TEST(ResultsMatch("london", search::Mode::Everywhere, rules), ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,31 +11,31 @@ namespace search
|
|||
{
|
||||
namespace tests_support
|
||||
{
|
||||
ExactMatch::ExactMatch(MwmSet::MwmId const & mwmId, TestFeature & feature)
|
||||
ExactMatchingRule::ExactMatchingRule(MwmSet::MwmId const & mwmId, TestFeature & feature)
|
||||
: m_mwmId(mwmId), m_feature(feature)
|
||||
{
|
||||
}
|
||||
|
||||
bool ExactMatch::Matches(FeatureType const & feature) const
|
||||
bool ExactMatchingRule::Matches(FeatureType const & feature) const
|
||||
{
|
||||
if (m_mwmId != feature.GetID().m_mwmId)
|
||||
return false;
|
||||
return m_feature.Matches(feature);
|
||||
}
|
||||
|
||||
string ExactMatch::ToString() const
|
||||
string ExactMatchingRule::ToString() const
|
||||
{
|
||||
ostringstream os;
|
||||
os << "ExactMatch [ " << DebugPrint(m_mwmId) << ", " << DebugPrint(m_feature) << " ]";
|
||||
os << "ExactMatchingRule [ " << DebugPrint(m_mwmId) << ", " << DebugPrint(m_feature) << " ]";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
AlternativesMatch::AlternativesMatch(initializer_list<shared_ptr<MatchingRule>> rules)
|
||||
AlternativesMatchingRule::AlternativesMatchingRule(initializer_list<shared_ptr<MatchingRule>> rules)
|
||||
: m_rules(move(rules))
|
||||
{
|
||||
}
|
||||
|
||||
bool AlternativesMatch::Matches(FeatureType const & feature) const
|
||||
bool AlternativesMatchingRule::Matches(FeatureType const & feature) const
|
||||
{
|
||||
for (auto const & rule : m_rules)
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ bool AlternativesMatch::Matches(FeatureType const & feature) const
|
|||
return false;
|
||||
}
|
||||
|
||||
string AlternativesMatch::ToString() const
|
||||
string AlternativesMatchingRule::ToString() const
|
||||
{
|
||||
ostringstream os;
|
||||
os << "OrRule [ ";
|
||||
|
|
|
@ -26,10 +26,10 @@ public:
|
|||
virtual string ToString() const = 0;
|
||||
};
|
||||
|
||||
class ExactMatch : public MatchingRule
|
||||
class ExactMatchingRule : public MatchingRule
|
||||
{
|
||||
public:
|
||||
ExactMatch(MwmSet::MwmId const & mwmId, TestFeature & feature);
|
||||
ExactMatchingRule(MwmSet::MwmId const & mwmId, TestFeature & feature);
|
||||
|
||||
// MatchingRule overrides:
|
||||
bool Matches(FeatureType const & feature) const override;
|
||||
|
@ -40,10 +40,10 @@ private:
|
|||
TestFeature & m_feature;
|
||||
};
|
||||
|
||||
class AlternativesMatch : public MatchingRule
|
||||
class AlternativesMatchingRule : public MatchingRule
|
||||
{
|
||||
public:
|
||||
AlternativesMatch(initializer_list<shared_ptr<MatchingRule>> rules);
|
||||
AlternativesMatchingRule(initializer_list<shared_ptr<MatchingRule>> rules);
|
||||
|
||||
// MatchingRule overrides:
|
||||
bool Matches(FeatureType const & feature) const override;
|
||||
|
@ -53,6 +53,18 @@ private:
|
|||
vector<shared_ptr<MatchingRule>> m_rules;
|
||||
};
|
||||
|
||||
template <typename... TArgs>
|
||||
shared_ptr<MatchingRule> ExactMatch(TArgs &&... args)
|
||||
{
|
||||
return make_shared<ExactMatchingRule>(forward<TArgs>(args)...);
|
||||
}
|
||||
|
||||
template <typename... TArgs>
|
||||
shared_ptr<MatchingRule> AlternativesMatch(TArgs &&... args)
|
||||
{
|
||||
return make_shared<AlternativesMatchingRule>(forward<TArgs>(args)...);
|
||||
}
|
||||
|
||||
bool MatchResults(Index const & index, vector<shared_ptr<MatchingRule>> rules,
|
||||
vector<search::Result> const & actual);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue