forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_count.cpp
More file actions
71 lines (57 loc) · 1.45 KB
/
Copy pathtest_count.cpp
File metadata and controls
71 lines (57 loc) · 1.45 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
#include "helpers.hpp"
#include <count.hpp>
#include <vector>
#include <iterator>
#include <utility>
#include "catch.hpp"
using iter::count;
TEST_CASE("count: watch for 10 elements", "[count]") {
std::vector<int> v{};
for (auto i : count()) {
v.push_back(i);
if (i == 9) break;
}
const std::vector<int> vc{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
REQUIRE(v == vc);
}
TEST_CASE("count: start at 10", "[count]") {
std::vector<int> v{};
for (auto i : count(10)) {
v.push_back(i);
if (i == 14) break;
}
const std::vector<int> vc{10, 11, 12, 13, 14};
REQUIRE(v == vc);
}
TEST_CASE("count: with step", "[count]") {
std::vector<int> v{};
for (auto i : count(2, -1)) {
v.push_back(i);
if (i == -3) break;
}
const std::vector<int> vc{2, 1, 0, -1, -2, -3};
REQUIRE(v == vc);
}
TEST_CASE("count: with step > 1", "[count]") {
std::vector<int> v{};
for (auto i : count(10, 2)) {
v.push_back(i);
if (i == 16) break;
}
const std::vector<int> vc{10, 12, 14, 16};
REQUIRE(v == vc);
}
TEST_CASE("count: can bo constexpr", "[count]") {
constexpr auto c = count();
constexpr auto c2 = count(5);
(void)c2;
constexpr auto c3 = count(5, 2);
(void)c3;
constexpr auto it = c.begin();
constexpr auto i = *it;
static_assert(i == 0, "count begin not correct value");
}
TEST_CASE("count: iterator meets requirements", "[count]") {
auto c = count();
REQUIRE(itertest::IsIterator<decltype(std::begin(c))>::value);
}