Skip to content

Commit 39146d2

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 7fd224e commit 39146d2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

unit/util/range.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,37 @@ 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).skip(2);
81+
auto it = range.begin();
82+
REQUIRE(*it == "acdef");
83+
range.drop(1);
84+
REQUIRE(range.empty());
85+
}
86+
THEN("Skip first 5 elements")
87+
{
88+
auto range = make_range(list).skip(5);
89+
REQUIRE(range.empty());
90+
}
6091
THEN(
6192
"A const instance of a `filter_iteratort` can mutate the input "
6293
"collection.")

0 commit comments

Comments
 (0)