forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_repeat.cpp
More file actions
73 lines (61 loc) · 1.79 KB
/
Copy pathtest_repeat.cpp
File metadata and controls
73 lines (61 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <repeat.hpp>
#include "helpers.hpp"
#include <vector>
#include <string>
#include <iterator>
#include "catch.hpp"
using iter::repeat;
TEST_CASE("repeat: one argument keeps giving value back", "[repeat]") {
auto r = repeat('a');
auto it = std::begin(r);
REQUIRE( *it == 'a' );
++it;
REQUIRE( *it == 'a' );
++it;
REQUIRE( *it == 'a' );
++it;
REQUIRE( *it == 'a' );
++it;
REQUIRE( *it == 'a' );
}
TEST_CASE("repeat: can be used as constexpr", "[repeat]") {
static constexpr char c = 'a';
{
constexpr auto r = repeat(c);
constexpr auto i = r.begin();
constexpr char c2 = *i;
static_assert(c == c2, "repeat value not as expected");
constexpr auto i2 = ++i; (void)i2;
}
{
constexpr auto r = repeat(c, 2);
constexpr auto i = r.begin();
constexpr char c2 = *i;
static_assert( c2 == c, "repeat value not as expected");
}
}
TEST_CASE("repeat: two argument repeats a number of times", "[repeat]") {
auto r = repeat('a', 3);
std::string s(std::begin(r), std::end(r));
REQUIRE( s == "aaa" );
}
TEST_CASE("repeat: 0 count gives empty sequence", "[repeat]") {
auto r = repeat('a', 0);
REQUIRE( std::begin(r) == std::end(r) );
}
TEST_CASE("repeat: negative count gives empty sequence", "[repeat]") {
auto r = repeat('a', -2);
REQUIRE( std::begin(r) == std::end(r) );
auto r2 = repeat('a', -1);
REQUIRE( std::begin(r2) == std::end(r2) );
}
TEST_CASE("repeat: doesn't duplicate item", "[repeat]") {
itertest::SolidInt si{2};
auto r = repeat(si);
auto it = std::begin(r);
(void)*it;
}
TEST_CASE("repeat: iterator meets requirements", "[repeat]") {
auto r = repeat(1);
REQUIRE( itertest::IsIterator<decltype(std::begin(r))>::value );
}