aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/iterator_ut.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/generic/iterator_ut.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/generic/iterator_ut.cpp')
-rw-r--r--util/generic/iterator_ut.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/util/generic/iterator_ut.cpp b/util/generic/iterator_ut.cpp
new file mode 100644
index 0000000000..00be19e10e
--- /dev/null
+++ b/util/generic/iterator_ut.cpp
@@ -0,0 +1,63 @@
+#include "iterator.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+Y_UNIT_TEST_SUITE(TIterator) {
+ Y_UNIT_TEST(ToForwardIteratorTest) {
+ TVector<int> x = {1, 2};
+ UNIT_ASSERT_VALUES_EQUAL(*std::prev(x.end()), *ToForwardIterator(x.rbegin()));
+ UNIT_ASSERT_VALUES_EQUAL(*ToForwardIterator(std::prev(x.rend())), *x.begin());
+ }
+}
+
+Y_UNIT_TEST_SUITE(TInputRangeAdaptor) {
+ class TSquaresGenerator: public TInputRangeAdaptor<TSquaresGenerator> {
+ public:
+ const i64* Next() {
+ Current_ = State_ * State_;
+ ++State_;
+ // Never return nullptr => we have infinite range!
+ return &Current_;
+ }
+
+ private:
+ i64 State_ = 0.0;
+ i64 Current_ = 0.0;
+ };
+
+ Y_UNIT_TEST(TSquaresGenerator) {
+ i64 cur = 0;
+ for (i64 sqr : TSquaresGenerator{}) {
+ UNIT_ASSERT_VALUES_EQUAL(cur * cur, sqr);
+
+ if (++cur > 10) {
+ break;
+ }
+ }
+ }
+
+ class TUrlPart: public TInputRangeAdaptor<TUrlPart> {
+ public:
+ TUrlPart(const TStringBuf& url)
+ : Url_(url)
+ {
+ }
+
+ NStlIterator::TProxy<TStringBuf> Next() {
+ return Url_.NextTok('/');
+ }
+
+ private:
+ TStringBuf Url_;
+ };
+
+ Y_UNIT_TEST(TUrlPart) {
+ const TVector<TStringBuf> expected = {TStringBuf("yandex.ru"), TStringBuf("search?")};
+ auto expected_part = expected.begin();
+ for (const TStringBuf& part : TUrlPart(TStringBuf("yandex.ru/search?"))) {
+ UNIT_ASSERT_VALUES_EQUAL(part, *expected_part);
+ ++expected_part;
+ }
+ UNIT_ASSERT(expected_part == expected.end());
+ }
+}