[util/generic] ut for TInputRangeAdaptor; [part 3];
@@ -9,3 +9,31 @@ Y_UNIT_TEST_SUITE(TIterator) {
UNIT_ASSERT_VALUES_EQUAL(*ToForwardIterator(std::prev(x.rend())), *x.begin());
}
}
+
+Y_UNIT_TEST_SUITE(TInputRangeAdaptor) {
+ class TSquaresGenerator : public TInputRangeAdaptor<TSquaresGenerator> {
+ public:
+ using TRetVal = const i64*;
+ TRetVal 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;
+ }
+ }
+ }
+}
