forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_chunked.cpp
More file actions
66 lines (53 loc) · 1.59 KB
/
Copy pathtest_chunked.cpp
File metadata and controls
66 lines (53 loc) · 1.59 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
#include <chunked.hpp>
#include <vector>
#include <array>
#include <string>
#include <utility>
#include "helpers.hpp"
#include "catch.hpp"
using iter::chunked;
using Vec = std::vector<int>;
using ResVec = std::vector<Vec>;
TEST_CASE("chunked: basic test", "[chunked]") {
Vec ns = {1,2,3,4,5,6};
ResVec results;
for (auto&& g : chunked(ns, 2)) {
results.emplace_back(std::begin(g), std::end(g));
}
ResVec rc = { {1, 2}, {3, 4}, {5, 6} };
REQUIRE( results == rc );
}
TEST_CASE("chunked: len(iterable) % groupsize != 0", "[chunked]") {
Vec ns = {1,2,3,4,5,6,7};
ResVec results;
for (auto&& g : chunked(ns, 3)) {
results.emplace_back(std::begin(g), std::end(g));
}
ResVec rc = { {1, 2, 3}, {4, 5, 6}, {7} };
REQUIRE( results == rc );
}
TEST_CASE("chunked: iterators can be compared", "[chunked]") {
Vec ns = {1,2,3,4,5,6,7};
auto g = chunked(ns, 3);
auto it = std::begin(g);
REQUIRE( it == std::begin(g) );
REQUIRE_FALSE( it != std::begin(g) );
++it;
REQUIRE( it != std::begin(g) );
REQUIRE_FALSE( it == std::begin(g) );
}
TEST_CASE("chunked: size 0 is empty", "[chunked]") {
Vec ns{1, 2, 3};
auto g = chunked(ns, 0);
REQUIRE( std::begin(g) == std::end(g) );
}
TEST_CASE("chunked: empty iterable gives empty chunked", "[chunked]") {
Vec ns{};
auto g = chunked(ns, 1);
REQUIRE( std::begin(g) == std::end(g) );
}
TEST_CASE("chunked: iterator meets requirements", "[chunked]") {
std::string s{};
auto c = chunked(s, 1);
REQUIRE( itertest::IsIterator<decltype(std::begin(c))>::value );
}