Skip to content

Commit 0b03e28

Browse files
committed
Add unit test of ranget having correct value_type
This commit adds a unit test, which tests the fix from the previous commit, because it is good to test things.
1 parent 879f530 commit 0b03e28

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

unit/util/range.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ Author: Romain Brenguier, [email protected]
1111
#include <testing-utils/catch.hpp>
1212
#include <util/range.h>
1313

14+
/// Trivial example template function requiring a container to have a
15+
/// `value_type`.
16+
template <typename containert>
17+
typename containert::value_type front(containert container)
18+
{
19+
return *container.begin();
20+
}
21+
1422
SCENARIO("range tests", "[core][util][range]")
1523
{
1624
GIVEN("A vector with three strings")
@@ -75,6 +83,18 @@ SCENARIO("range tests", "[core][util][range]")
7583
const std::vector<int> expected_odds{1, 3};
7684
REQUIRE(odds == expected_odds);
7785
}
86+
THEN(
87+
"The unit testing template function requiring `value_type` works with "
88+
"`std::vector`.")
89+
{
90+
REQUIRE(front(input) == 1);
91+
}
92+
THEN(
93+
"A range can be used with a template function expecting a container "
94+
"which has a `value_type`.")
95+
{
96+
REQUIRE(front(make_range(input)) == 1);
97+
}
7898
}
7999
GIVEN("Two const vectors of ints")
80100
{

0 commit comments

Comments
 (0)