Skip to content

Commit 130a539

Browse files
Add unit tests for ranget::zip
This tests that the zip method behaves as expected on a vector of int and a list of strings zipped together.
1 parent 0c0d997 commit 130a539

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

unit/util/range.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Author: Romain Brenguier, [email protected]
66
77
\*******************************************************************/
88

9+
#include <list>
910
#include <vector>
1011

1112
#include <testing-utils/use_catch.h>
@@ -188,6 +189,34 @@ SCENARIO("range tests", "[core][util][range]")
188189
REQUIRE(input2 == expected_result2);
189190
}
190191
}
192+
GIVEN("A vectors of int and a list of strings.")
193+
{
194+
std::vector<int> int_vector{1, 2};
195+
std::list<std::string> string_list{"foo", "bar"};
196+
WHEN("We zip the vector and the list")
197+
{
198+
auto range = make_range(int_vector).zip(string_list);
199+
REQUIRE(!range.empty());
200+
THEN("First pair is (1, foo)")
201+
{
202+
const std::pair<int, std::string> first_pair = *range.begin();
203+
REQUIRE(first_pair.first == 1);
204+
REQUIRE(first_pair.second == "foo");
205+
}
206+
range = std::move(range).drop(1);
207+
THEN("Second pair is (2, bar)")
208+
{
209+
const std::pair<int, std::string> second_pair = *range.begin();
210+
REQUIRE(second_pair.first == 2);
211+
REQUIRE(second_pair.second == "bar");
212+
}
213+
range = std::move(range).drop(1);
214+
THEN("Range is empty")
215+
{
216+
REQUIRE(range.empty());
217+
}
218+
}
219+
}
191220
}
192221

193222
class move_onlyt

0 commit comments

Comments
 (0)