diff options
author | Yuri Gorshenin <y@maps.me> | 2016-03-11 17:44:01 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:53:01 +0300 |
commit | 575d9eb26d3870b94be38cba5abb48c33b33a45f (patch) | |
tree | e242f4e75313991dc0a54f1d21358c29a87c28ab /base/base_tests | |
parent | bc44c63d03d32c8f77c9f208f38b8df443a07130 (diff) |
[search] Used linear model for rank calculation.
Diffstat (limited to 'base/base_tests')
-rw-r--r-- | base/base_tests/stl_helpers_test.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/base/base_tests/stl_helpers_test.cpp b/base/base_tests/stl_helpers_test.cpp index 00b59ab302..7d23bdd3d2 100644 --- a/base/base_tests/stl_helpers_test.cpp +++ b/base/base_tests/stl_helpers_test.cpp @@ -6,7 +6,20 @@ #include "std/utility.hpp" #include "std/vector.hpp" -UNIT_TEST(CompareBy_Smoke) +namespace +{ +class Int +{ +public: + explicit Int(int v) : m_v(v) {} + + inline int Get() const { return m_v; } + +private: + int m_v; +}; + +UNIT_TEST(CompareBy_Field) { vector<pair<int, int>> v = {{2, 2}, {0, 4}, {3, 1}, {4, 0}, {1, 3}}; sort(v.begin(), v.end(), my::CompareBy(&pair<int, int>::first)); @@ -21,3 +34,15 @@ UNIT_TEST(CompareBy_Smoke) for (size_t i = 0; i < pv.size(); ++i) TEST_EQUAL(i, pv[i]->second, ()); } + +UNIT_TEST(CompareBy_Method) +{ + vector<Int> v; + for (int i = 9; i >= 0; --i) + v.emplace_back(i); + + sort(v.begin(), v.end(), my::CompareBy(&Int::Get)); + for (size_t i = 0; i < v.size(); ++i) + TEST_EQUAL(v[i].Get(), static_cast<int>(i), ()); +} +} // namespace |