[search] Add PreferCountry RankingInfo test.

This commit is contained in:
tatiana-yan 2020-04-07 19:08:34 +03:00 committed by mpimenov
parent cf1c8370f1
commit 184a1663da

View file

@ -2,6 +2,7 @@
#include "search/query_params.hpp"
#include "search/ranking_utils.hpp"
#include "search/ranking_info.hpp"
#include "search/token_range.hpp"
#include "search/token_slice.hpp"
@ -68,4 +69,30 @@ UNIT_TEST(NameTest_Smoke)
test("фото на документы", "фото", TokenRange(0, 1), NAME_SCORE_PREFIX, 0);
test("фотоателье", "фото", TokenRange(0, 1), NAME_SCORE_PREFIX, 0);
}
UNIT_TEST(PreferCountry)
{
RankingInfo info;
info.m_nameScore = NAME_SCORE_FULL_MATCH;
info.m_errorsMade = ErrorsMade(0);
info.m_numTokens = 1;
info.m_matchedFraction = 1.0;
info.m_allTokensUsed = true;
info.m_exactMatch = true;
auto cafe = info;
cafe.m_distanceToPivot = 1e3;
cafe.m_tokenRanges[Model::TYPE_POI] = TokenRange(0, 1);
cafe.m_exactCountryOrCapital = false;
cafe.m_type = Model::TYPE_POI;
auto country = info;
country.m_distanceToPivot = 1e6;
country.m_tokenRanges[Model::TYPE_COUNTRY] = TokenRange(0, 1);
country.m_exactCountryOrCapital = true;
country.m_type = Model::TYPE_COUNTRY;
// Country should be preferred even if cafe is much closer to viewport center.
TEST_LESS(cafe.GetLinearModelRank(), country.GetLinearModelRank(),());
}
} // namespace