Sorting tests for search::Results.

This commit is contained in:
VladiMihaylenko 2018-01-29 19:28:04 +03:00 committed by mpimenov
parent 2dd27743b6
commit f3edb952b9
2 changed files with 38 additions and 0 deletions

View file

@ -20,6 +20,7 @@ set(
point_rect_matcher_tests.cpp
query_saver_tests.cpp
ranking_tests.cpp
results_tests.cpp
region_info_getter_tests.cpp
segment_tree_tests.cpp
string_match_test.cpp

View file

@ -0,0 +1,37 @@
#include "testing/testing.hpp"
#include "search/result.hpp"
#include <iterator>
namespace search
{
UNIT_TEST(Sorting_Test)
{
Results r;
MwmSet::MwmId id;
for (uint32_t i = 5; i != 0; --i)
{
r.AddResultNoChecks({{id, i}, {} /* pt */, {} /* str */, {} /* address */,
{} /* featureTypeName */, {} /* featureType */, {} /* metadata */});
}
for (auto it = r.begin(); it != r.end(); ++it)
{
auto const & result = *it;
TEST_EQUAL(result.GetFeatureID().m_index, std::distance(it, r.end()), ());
TEST_EQUAL(result.GetPositionInResults(), std::distance(r.begin(), it), ());
}
r.SortBy([](auto const & lhs, auto const & rhs) {
return lhs.GetFeatureID().m_index < rhs.GetFeatureID().m_index;
});
for (auto it = r.begin(); it != r.end(); ++it)
{
auto const & result = *it;
TEST_EQUAL(result.GetFeatureID().m_index, std::distance(r.begin(), it) + 1, ());
TEST_EQUAL(result.GetPositionInResults(), std::distance(r.begin(), it), ());
}
}
} // namespace search