Skip to content

Commit d6b5acb

Browse files
Unit test for ranget drop and skip
This tests that these operations behave as expected and gives examples on how to use them.
1 parent 1c54586 commit d6b5acb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

unit/util/range.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,45 @@ SCENARIO("range tests", "[core][util][range]")
5757
++it;
5858
REQUIRE(it == filtered_range.end());
5959
}
60+
THEN("Drop first 2 elements")
61+
{
62+
auto range = make_range(list);
63+
const bool elements_left = range.drop(2);
64+
REQUIRE(elements_left);
65+
auto it = range.begin();
66+
REQUIRE(*it == "acdef");
67+
const bool more_elements_left = range.drop(1);
68+
REQUIRE(!more_elements_left);
69+
REQUIRE(range.empty());
70+
}
71+
THEN("Drop first 5 elements")
72+
{
73+
auto range = make_range(list);
74+
const bool elements_left = range.drop(5);
75+
REQUIRE(!elements_left);
76+
REQUIRE(range.empty());
77+
}
78+
THEN("Skip first 2 elements")
79+
{
80+
auto range = make_range(list);
81+
auto skip_range = range.skip(2);
82+
auto it = skip_range.begin();
83+
REQUIRE(*it == "acdef");
84+
skip_range.drop(1);
85+
REQUIRE(skip_range.empty());
86+
// Check the original is unmodified
87+
REQUIRE(!range.empty());
88+
REQUIRE(*range.begin() == "abc");
89+
}
90+
THEN("Skip first 5 elements")
91+
{
92+
auto range = make_range(list);
93+
auto skip_range = range.skip(5);
94+
REQUIRE(skip_range.empty());
95+
// Check the original is unmodified
96+
REQUIRE(!range.empty());
97+
REQUIRE(*range.begin() == "abc");
98+
}
6099
THEN(
61100
"A const instance of a `filter_iteratort` can mutate the input "
62101
"collection.")

0 commit comments

Comments
 (0)