aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/range_walker_ut.cpp
blob: d6a86cc804820bd1fcbe5517acf88eebf949ffa5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "range_walker.h"

#include <library/cpp/testing/unittest/registar.h>

using namespace NYql;

Y_UNIT_TEST_SUITE(TRangeWalkerTests) {
    Y_UNIT_TEST(InvalidRange) {
        UNIT_ASSERT_EXCEPTION_CONTAINS(TRangeWalker<int>(2, 1), yexception, "Invalid range for walker");
    }

    Y_UNIT_TEST(SingleValueRange) {
        TRangeWalker<int> w(5, 5);
        UNIT_ASSERT_EQUAL(5, w.GetStart());
        UNIT_ASSERT_EQUAL(5, w.GetFinish());
        UNIT_ASSERT_EQUAL(1, w.GetRangeSize());

        for (int i = 0; i < 10; ++i) {
            UNIT_ASSERT_EQUAL(5, w.MoveToNext());
        }
    }

    Y_UNIT_TEST(ManyValuesRange) {
        TRangeWalker<int> w(5, 7);
        UNIT_ASSERT_EQUAL(5, w.GetStart());
        UNIT_ASSERT_EQUAL(7, w.GetFinish());
        UNIT_ASSERT_EQUAL(3, w.GetRangeSize());

        for (int i = 0; i < 10; ++i) {
            UNIT_ASSERT_EQUAL(5, w.MoveToNext());
            UNIT_ASSERT_EQUAL(6, w.MoveToNext());
            UNIT_ASSERT_EQUAL(7, w.MoveToNext());
        }
    }
}