diff options
author | Mikhail Borisov <borisov.mikhail@gmail.com> | 2022-02-10 16:45:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:39 +0300 |
commit | a6a92afe03e02795227d2641b49819b687f088f8 (patch) | |
tree | f6984a1d27d5a7ec88a6fdd6e20cd5b7693b6ece /util/generic/algorithm_ut.cpp | |
parent | c6dc8b8bd530985bc4cce0137e9a5de32f1087cb (diff) | |
download | ydb-a6a92afe03e02795227d2641b49819b687f088f8.tar.gz |
Restoring authorship annotation for Mikhail Borisov <borisov.mikhail@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/generic/algorithm_ut.cpp')
-rw-r--r-- | util/generic/algorithm_ut.cpp | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index 8d732fcc0c..58a3b56956 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -446,61 +446,61 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(SortTestTwoIterators) { - TVector<int> collection = {10, 2, 7}; - Sort(collection.begin(), collection.end()); - TVector<int> expected = {2, 7, 10}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + Sort(collection.begin(), collection.end()); + TVector<int> expected = {2, 7, 10}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(SortTestTwoIteratorsAndComparator) { - TVector<int> collection = {10, 2, 7}; - Sort(collection.begin(), collection.end(), [](int l, int r) { return l > r; }); - TVector<int> expected = {10, 7, 2}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + Sort(collection.begin(), collection.end(), [](int l, int r) { return l > r; }); + TVector<int> expected = {10, 7, 2}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(SortTestContainer) { - TVector<int> collection = {10, 2, 7}; - Sort(collection); - TVector<int> expected = {2, 7, 10}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + Sort(collection); + TVector<int> expected = {2, 7, 10}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(SortTestContainerAndComparator) { - TVector<int> collection = {10, 2, 7}; - Sort(collection, [](int l, int r) { return l > r; }); - TVector<int> expected = {10, 7, 2}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + Sort(collection, [](int l, int r) { return l > r; }); + TVector<int> expected = {10, 7, 2}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(StableSortTestTwoIterators) { - TVector<int> collection = {10, 2, 7}; - StableSort(collection.begin(), collection.end()); - TVector<int> expected = {2, 7, 10}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + StableSort(collection.begin(), collection.end()); + TVector<int> expected = {2, 7, 10}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(StableSortTestTwoIteratorsAndComparator) { - TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; - StableSort(collection.begin(), collection.end(), [](int l, int r) { return (l / 100) < (r / 100); }); - TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; + StableSort(collection.begin(), collection.end(), [](int l, int r) { return (l / 100) < (r / 100); }); + TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(StableSortTestContainer) { - TVector<int> collection = {10, 2, 7}; - StableSort(collection); - TVector<int> expected = {2, 7, 10}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + StableSort(collection); + TVector<int> expected = {2, 7, 10}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(StableSortTestContainerAndComparator) { - TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; - StableSort(collection, [](int l, int r) { return (l / 100) < (r / 100); }); - TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; + StableSort(collection, [](int l, int r) { return (l / 100) < (r / 100); }); + TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(SortByTest) { TVector<int> collection = {10, 2, 7}; SortBy(collection, [](int x) { return -x; }); @@ -796,45 +796,45 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { auto i = FindIf(range, [](auto) { return false; }); Y_UNUSED(i); } - + Y_UNIT_TEST(TestLowerBoundBy) { using TIntPairs = TVector<std::pair<i32, i32>>; - - auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; - auto getKey = [](const auto& x) { return x.second; }; - - StableSortBy(data, getKey); - - auto it = LowerBoundBy(data.begin(), data.end(), 4, getKey); - UNIT_ASSERT(it != data.end()); - UNIT_ASSERT_EQUAL(it->second, 4); - UNIT_ASSERT_EQUAL(it->first, 3); - - UNIT_ASSERT(it > data.begin()); - UNIT_ASSERT_EQUAL((it - 1)->second, 2); - - UNIT_ASSERT((it + 1) < data.end()); - UNIT_ASSERT_EQUAL((it + 1)->second, 4); - } - + + auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; + auto getKey = [](const auto& x) { return x.second; }; + + StableSortBy(data, getKey); + + auto it = LowerBoundBy(data.begin(), data.end(), 4, getKey); + UNIT_ASSERT(it != data.end()); + UNIT_ASSERT_EQUAL(it->second, 4); + UNIT_ASSERT_EQUAL(it->first, 3); + + UNIT_ASSERT(it > data.begin()); + UNIT_ASSERT_EQUAL((it - 1)->second, 2); + + UNIT_ASSERT((it + 1) < data.end()); + UNIT_ASSERT_EQUAL((it + 1)->second, 4); + } + Y_UNIT_TEST(TestUpperBoundBy) { using TIntPairs = TVector<std::pair<i32, i32>>; - - auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; - auto getKey = [](const auto& x) { return x.second; }; - - StableSortBy(data, getKey); - - auto it = UpperBoundBy(data.begin(), data.end(), 4, getKey); - UNIT_ASSERT(it != data.end()); - UNIT_ASSERT_EQUAL(it->second, 5); - UNIT_ASSERT_EQUAL(it->first, 1); - - UNIT_ASSERT(it > data.begin()); - UNIT_ASSERT_EQUAL((it - 1)->second, 4); - - UNIT_ASSERT((it + 1) == data.end()); - } + + auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; + auto getKey = [](const auto& x) { return x.second; }; + + StableSortBy(data, getKey); + + auto it = UpperBoundBy(data.begin(), data.end(), 4, getKey); + UNIT_ASSERT(it != data.end()); + UNIT_ASSERT_EQUAL(it->second, 5); + UNIT_ASSERT_EQUAL(it->first, 1); + + UNIT_ASSERT(it > data.begin()); + UNIT_ASSERT_EQUAL((it - 1)->second, 4); + + UNIT_ASSERT((it + 1) == data.end()); + } Y_UNIT_TEST(TestFindInContainer) { std::vector<int> v = {1, 2, 1000, 15, 100}; |