diff options
author | yazevnul <yazevnul@yandex-team.ru> | 2022-02-10 16:46:46 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:46 +0300 |
commit | 8cbc307de0221f84c80c42dcbe07d40727537e2c (patch) | |
tree | 625d5a673015d1df891e051033e9fcde5c7be4e5 /util/generic/algorithm_ut.cpp | |
parent | 30d1ef3941e0dc835be7609de5ebee66958f215a (diff) | |
download | ydb-8cbc307de0221f84c80c42dcbe07d40727537e2c.tar.gz |
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/algorithm_ut.cpp')
-rw-r--r-- | util/generic/algorithm_ut.cpp | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index 8d732fcc0c..fc2a05efb9 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -6,8 +6,8 @@ static auto isOne = [](char c) { return c == '1'; }; -Y_UNIT_TEST_SUITE(TAlgorithm) { - Y_UNIT_TEST(AnyTest) { +Y_UNIT_TEST_SUITE(TAlgorithm) { + Y_UNIT_TEST(AnyTest) { UNIT_ASSERT(0 == AnyOf(TStringBuf("00"), isOne)); UNIT_ASSERT(1 == AnyOf(TStringBuf("01"), isOne)); UNIT_ASSERT(1 == AnyOf(TStringBuf("10"), isOne)); @@ -20,7 +20,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(1 == AnyOf(array01, isOne)); } - Y_UNIT_TEST(AllOfTest) { + Y_UNIT_TEST(AllOfTest) { UNIT_ASSERT(0 == AllOf(TStringBuf("00"), isOne)); UNIT_ASSERT(0 == AllOf(TStringBuf("01"), isOne)); UNIT_ASSERT(0 == AllOf(TStringBuf("10"), isOne)); @@ -33,7 +33,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(1 == AllOf(array11, isOne)); } - Y_UNIT_TEST(CountIfTest) { + Y_UNIT_TEST(CountIfTest) { UNIT_ASSERT(3 == CountIf(TStringBuf("____1________1____1_______"), isOne)); UNIT_ASSERT(5 == CountIf(TStringBuf("1____1________1____1_______1"), isOne)); UNIT_ASSERT(0 == CountIf(TStringBuf("___________"), isOne)); @@ -68,40 +68,40 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { void operator=(const TStrokaNoCopy&); }; - Y_UNIT_TEST(CountOfTest) { - UNIT_ASSERT_VALUES_EQUAL(CountOf(1, 2), 0); - UNIT_ASSERT_VALUES_EQUAL(CountOf(1, 1), 1); - UNIT_ASSERT_VALUES_EQUAL(CountOf(2, 4, 5), 0); - UNIT_ASSERT_VALUES_EQUAL(CountOf(2, 4, 2), 1); - UNIT_ASSERT_VALUES_EQUAL(CountOf(3, 3, 3), 2); - - // Checking comparison of different types. - UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'x', 'y', 'z'), 0); - UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'a', 'b', 'c', 0x61), 2); - UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'a', 'b', 'c', 0x61ll), 2); - + Y_UNIT_TEST(CountOfTest) { + UNIT_ASSERT_VALUES_EQUAL(CountOf(1, 2), 0); + UNIT_ASSERT_VALUES_EQUAL(CountOf(1, 1), 1); + UNIT_ASSERT_VALUES_EQUAL(CountOf(2, 4, 5), 0); + UNIT_ASSERT_VALUES_EQUAL(CountOf(2, 4, 2), 1); + UNIT_ASSERT_VALUES_EQUAL(CountOf(3, 3, 3), 2); + + // Checking comparison of different types. + UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'x', 'y', 'z'), 0); + UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'a', 'b', 'c', 0x61), 2); + UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'a', 'b', 'c', 0x61ll), 2); + // TString and const char * UNIT_ASSERT_VALUES_EQUAL(CountOf(TString("xyz"), "123", "poi"), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(TString("xyz"), "123", "poi", "xyz"), 1); - + // TString and TStringBuf UNIT_ASSERT_VALUES_EQUAL(CountOf(TString("xyz"), TStringBuf("123"), TStringBuf("poi")), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(TString("xyz"), TStringBuf("123"), TStringBuf("poi"), TStringBuf("xyz")), 1); - - // TStringBuf and const char * + + // TStringBuf and const char * UNIT_ASSERT_VALUES_EQUAL(CountOf(TStringBuf("xyz"), "123", "poi"), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(TStringBuf("xyz"), "123", "poi", "xyz"), 1); - + // TStringBuf and TString UNIT_ASSERT_VALUES_EQUAL(CountOf(TStringBuf("xyz"), TString("123"), TString("poi")), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(TStringBuf("xyz"), TString("123"), TString("poi"), TString("xyz")), 1); - } - - Y_UNIT_TEST(EqualToOneOfTest) { + } + + Y_UNIT_TEST(EqualToOneOfTest) { UNIT_ASSERT(1 == EqualToOneOf(1, 1, 2)); UNIT_ASSERT(1 == EqualToOneOf(2, 1, 2)); UNIT_ASSERT(0 == EqualToOneOf(3, 1, 2)); @@ -141,7 +141,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { template <class TTestConstPtr> void TestFindIfPtrFoundValue(int j, TTestConstPtr root) { if (j == 3) { - UNIT_ASSERT(root == nullptr); + UNIT_ASSERT(root == nullptr); } else if (j == 4) { UNIT_ASSERT(root && *root == 2); } else { @@ -203,7 +203,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } } - Y_UNIT_TEST(FindIndexTest) { + Y_UNIT_TEST(FindIndexTest) { TVectorNoCopy v; v.push_back(1); v.push_back(2); @@ -247,7 +247,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_EQUAL(NPOS, FindIndexIf(empty, [](int x) { return x == 3; })); } - Y_UNIT_TEST(SortUniqueTest) { + Y_UNIT_TEST(SortUniqueTest) { { TVector<TString> v; SortUnique(v); @@ -266,21 +266,21 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } } - Y_UNIT_TEST(EraseTest) { + Y_UNIT_TEST(EraseTest) { TVector<int> data = {5, 4, 3, 2, 1, 0}; TVector<int> expected = {5, 4, 2, 1, 0}; Erase(data, 3); UNIT_ASSERT_EQUAL(data, expected); } - Y_UNIT_TEST(EraseIfTest) { + Y_UNIT_TEST(EraseIfTest) { TVector<int> data = {5, 4, 3, 2, 1, 0}; TVector<int> expected = {2, 1, 0}; EraseIf(data, [](int i) { return i >= 3; }); UNIT_ASSERT_EQUAL(data, expected); } - Y_UNIT_TEST(EraseNodesIfTest) { + Y_UNIT_TEST(EraseNodesIfTest) { TMap<int, int> map{{1, 1}, {2, 2}, {3, 5}}; TMap<int, int> expectedMap{{1, 1}}; EraseNodesIf(map, [](auto p) { return p.first >= 2; }); @@ -312,7 +312,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_EQUAL(hashMultiMap, expectedHashMultiMap); } - Y_UNIT_TEST(NthElementTest) { + Y_UNIT_TEST(NthElementTest) { { TVector<TString> v; NthElement(v.begin(), v.begin(), v.end()); @@ -348,7 +348,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } } - Y_UNIT_TEST(BinarySearchTest) { + Y_UNIT_TEST(BinarySearchTest) { { TVector<TString> v; bool test = BinarySearch(v.begin(), v.end(), "test"); @@ -358,10 +358,10 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { { int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; - bool test = BinarySearch(data, data + Y_ARRAY_SIZE(data), 2); + bool test = BinarySearch(data, data + Y_ARRAY_SIZE(data), 2); UNIT_ASSERT_EQUAL(test, true); - test = BinarySearch(data, data + Y_ARRAY_SIZE(data), 10); + test = BinarySearch(data, data + Y_ARRAY_SIZE(data), 10); UNIT_ASSERT_EQUAL(test, false); } @@ -379,7 +379,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } } - Y_UNIT_TEST(EqualRangeTest) { + Y_UNIT_TEST(EqualRangeTest) { { TVector<TString> v; using PairOfVector = std::pair<TVector<TString>::iterator, TVector<TString>::iterator>; @@ -392,11 +392,11 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { { int data[] = {1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 5}; using PairOfInt = std::pair<int*, int*>; - PairOfInt tmp = EqualRange(data, data + Y_ARRAY_SIZE(data), 3); + PairOfInt tmp = EqualRange(data, data + Y_ARRAY_SIZE(data), 3); UNIT_ASSERT_EQUAL(tmp.second - tmp.first, 4); UNIT_ASSERT_EQUAL(tmp.first - data, 7); - UNIT_ASSERT_EQUAL(data + Y_ARRAY_SIZE(data) - tmp.second, 2); + UNIT_ASSERT_EQUAL(data + Y_ARRAY_SIZE(data) - tmp.second, 2); } { @@ -416,7 +416,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } } - Y_UNIT_TEST(IsSortedTest) { + Y_UNIT_TEST(IsSortedTest) { TVector<int> v0; UNIT_ASSERT_VALUES_EQUAL(IsSorted(v0.begin(), v0.end()), true); @@ -445,91 +445,91 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_VALUES_EQUAL(IsSortedBy(v3.begin(), v3.end(), std::negate<int>()), false); } - Y_UNIT_TEST(SortTestTwoIterators) { + 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); } - Y_UNIT_TEST(SortTestTwoIteratorsAndComparator) { + 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); } - Y_UNIT_TEST(SortTestContainer) { + Y_UNIT_TEST(SortTestContainer) { TVector<int> collection = {10, 2, 7}; Sort(collection); TVector<int> expected = {2, 7, 10}; UNIT_ASSERT_VALUES_EQUAL(collection, expected); } - Y_UNIT_TEST(SortTestContainerAndComparator) { + 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); } - Y_UNIT_TEST(StableSortTestTwoIterators) { + 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); } - Y_UNIT_TEST(StableSortTestTwoIteratorsAndComparator) { + 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); } - Y_UNIT_TEST(StableSortTestContainer) { + Y_UNIT_TEST(StableSortTestContainer) { TVector<int> collection = {10, 2, 7}; StableSort(collection); TVector<int> expected = {2, 7, 10}; UNIT_ASSERT_VALUES_EQUAL(collection, expected); } - Y_UNIT_TEST(StableSortTestContainerAndComparator) { + 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); } - Y_UNIT_TEST(SortByTest) { + Y_UNIT_TEST(SortByTest) { TVector<int> collection = {10, 2, 7}; SortBy(collection, [](int x) { return -x; }); TVector<int> expected = {10, 7, 2}; UNIT_ASSERT_VALUES_EQUAL(collection, expected); } - Y_UNIT_TEST(StableSortByTest) { + Y_UNIT_TEST(StableSortByTest) { TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; StableSortBy(collection, [](int x) { return x / 100; }); TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; UNIT_ASSERT_VALUES_EQUAL(collection, expected); } - Y_UNIT_TEST(SortUniqueByTest) { + Y_UNIT_TEST(SortUniqueByTest) { TVector<int> collection = {404, 101, 101, 203, 101, 203, 404}; StableSortUniqueBy(collection, [](int x) { return x / 100; }); TVector<int> expected = {101, 203, 404}; UNIT_ASSERT_VALUES_EQUAL(collection, expected); } - Y_UNIT_TEST(StableSortUniqueByTest) { + Y_UNIT_TEST(StableSortUniqueByTest) { TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; StableSortUniqueBy(collection, [](int x) { return x / 100; }); TVector<int> expected = {101, 203, 404}; UNIT_ASSERT_VALUES_EQUAL(collection, expected); } - Y_UNIT_TEST(IotaTest) { + Y_UNIT_TEST(IotaTest) { TVector<int> v(10); Iota(v.begin(), v.end(), 0); @@ -543,7 +543,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_VALUES_EQUAL(v[9], 9); } - Y_UNIT_TEST(CopyNTest) { + Y_UNIT_TEST(CopyNTest) { int data[] = {1, 2, 3, 4, 8, 7, 6, 5}; const size_t vSize = 10; TVector<int> result(10, 0); @@ -575,7 +575,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } } - Y_UNIT_TEST(CopyIfTest) { + Y_UNIT_TEST(CopyIfTest) { const size_t count = 9; int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; const size_t vSize = 10; @@ -590,7 +590,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } } - Y_UNIT_TEST(MinMaxElementTest) { + Y_UNIT_TEST(MinMaxElementTest) { TVector<int> v(10); Iota(v.begin(), v.end(), 0); UNIT_ASSERT_EQUAL(*MinMaxElement(v.begin(), v.end()).first, 0); @@ -602,7 +602,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_EQUAL(*MinMaxElement(v.begin(), v.end()).second, 11); } - Y_UNIT_TEST(MinMaxTest) { + Y_UNIT_TEST(MinMaxTest) { std::pair<int, int> p1 = MinMax(5, 12); UNIT_ASSERT_EQUAL(p1.first, 5); UNIT_ASSERT_EQUAL(p1.second, 12); @@ -612,7 +612,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_EQUAL(p2.second, TString("test")); } - Y_UNIT_TEST(TestMaxElementBy) { + Y_UNIT_TEST(TestMaxElementBy) { const int array[] = {1, 2, 5, 3, 4, 5}; UNIT_ASSERT_VALUES_EQUAL(*MaxElementBy(array, [](int x) { return x * x; @@ -638,7 +638,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_STRINGS_EQUAL(*MaxElementBy(strings, [](TString s) { return s.size(); }), "three"); } - Y_UNIT_TEST(TestMinElementBy) { + Y_UNIT_TEST(TestMinElementBy) { const int array[] = {2, 3, 4, 1, 5}; UNIT_ASSERT_VALUES_EQUAL(*MinElementBy(array, [](int x) -> char { return 'a' + x; @@ -668,12 +668,12 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_STRINGS_EQUAL(*MinElementBy(strings.rbegin(), strings.rend(), stringLength), "two"); } - Y_UNIT_TEST(MaxElementByReturnsEndForEmptyRange) { + Y_UNIT_TEST(MaxElementByReturnsEndForEmptyRange) { const TVector<int> empty; UNIT_ASSERT_EQUAL(MaxElementBy(empty, [](int) { return 0; }), empty.end()); } - Y_UNIT_TEST(MaxElementByDoesntCallFunctorForEmptyRange) { + Y_UNIT_TEST(MaxElementByDoesntCallFunctorForEmptyRange) { const TVector<int> empty; auto functor = [](int) { UNIT_ASSERT(false); @@ -682,12 +682,12 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { MaxElementBy(empty, functor); } - Y_UNIT_TEST(MinElementByReturnsEndForEmptyRange) { + Y_UNIT_TEST(MinElementByReturnsEndForEmptyRange) { const TVector<int> empty; UNIT_ASSERT_EQUAL(MinElementBy(empty, [](int) { return 0; }), empty.end()); } - Y_UNIT_TEST(MinElementByDoesntCallFunctorForEmptyRange) { + Y_UNIT_TEST(MinElementByDoesntCallFunctorForEmptyRange) { const TVector<int> empty; auto functor = [](int) { UNIT_ASSERT(false); @@ -756,7 +756,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } } - Y_UNIT_TEST(FindIfForContainer) { + Y_UNIT_TEST(FindIfForContainer) { using std::begin; using std::end; @@ -790,14 +790,14 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { return &r + 1; } - Y_UNIT_TEST(FindIfForUserType) { + Y_UNIT_TEST(FindIfForUserType) { // Compileability test. Should work for user types with begin/end overloads TRange range; auto i = FindIf(range, [](auto) { return false; }); Y_UNUSED(i); } - Y_UNIT_TEST(TestLowerBoundBy) { + Y_UNIT_TEST(TestLowerBoundBy) { using TIntPairs = TVector<std::pair<i32, i32>>; auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; @@ -817,7 +817,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_EQUAL((it + 1)->second, 4); } - Y_UNIT_TEST(TestUpperBoundBy) { + Y_UNIT_TEST(TestUpperBoundBy) { using TIntPairs = TVector<std::pair<i32, i32>>; auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; @@ -836,7 +836,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT((it + 1) == data.end()); } - Y_UNIT_TEST(TestFindInContainer) { + Y_UNIT_TEST(TestFindInContainer) { std::vector<int> v = {1, 2, 1000, 15, 100}; UNIT_ASSERT(Find(v, 5) == v.end()); UNIT_ASSERT(Find(v, 1) == v.begin()); |