range_walker_ut.cpp 1015 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "range_walker.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. using namespace NYql;
  4. Y_UNIT_TEST_SUITE(TRangeWalkerTests) {
  5. Y_UNIT_TEST(InvalidRange) {
  6. UNIT_ASSERT_EXCEPTION_CONTAINS(TRangeWalker<int>(2, 1), yexception, "Invalid range for walker");
  7. }
  8. Y_UNIT_TEST(SingleValueRange) {
  9. TRangeWalker<int> w(5, 5);
  10. UNIT_ASSERT_EQUAL(5, w.GetStart());
  11. UNIT_ASSERT_EQUAL(5, w.GetFinish());
  12. UNIT_ASSERT_EQUAL(1, w.GetRangeSize());
  13. for (int i = 0; i < 10; ++i) {
  14. UNIT_ASSERT_EQUAL(5, w.MoveToNext());
  15. }
  16. }
  17. Y_UNIT_TEST(ManyValuesRange) {
  18. TRangeWalker<int> w(5, 7);
  19. UNIT_ASSERT_EQUAL(5, w.GetStart());
  20. UNIT_ASSERT_EQUAL(7, w.GetFinish());
  21. UNIT_ASSERT_EQUAL(3, w.GetRangeSize());
  22. for (int i = 0; i < 10; ++i) {
  23. UNIT_ASSERT_EQUAL(5, w.MoveToNext());
  24. UNIT_ASSERT_EQUAL(6, w.MoveToNext());
  25. UNIT_ASSERT_EQUAL(7, w.MoveToNext());
  26. }
  27. }
  28. }