forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestrange.cpp
More file actions
83 lines (68 loc) · 1.82 KB
/
Copy pathtestrange.cpp
File metadata and controls
83 lines (68 loc) · 1.82 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
74
75
76
77
78
79
80
81
82
83
#include <range.hpp>
#include <iostream>
using iter::range;
int main()
{
for (auto i : range(10)) {
std::cout << i << std::endl;
}
for (auto i : range(20, 30)) {
std::cout << i << std::endl;
}
for (auto i : range(50, 60, 2)) {
std::cout << i << std::endl;
}
std::cout << "Negative Tests\n";
for (auto i: range(-10, 0)) {
std::cout << i << std::endl;
}
for (auto i : range(-10, 10, 2)) {
std::cout << i << std::endl;
}
std::cout << "Tests where (stop - start)%step != 0" << std::endl;
for (auto i : range(1, 10, 2)) {
std::cout << i << std::endl;
}
for (auto i : range(-1, -10, -2)) {
std::cout << i << std::endl;
}
std::cout << "Tests with different types" << std::endl;
for(auto i : range(5.0, 10.0, 0.5)) {
std::cout << i << std::endl;
}
std::cout << "test unsigned" << std::endl;
std::cout << "empty range: " << std::endl;
size_t len = 0;
for(auto i : range(len)){
std::cout << i << std::endl;
}
std::cout << "stop only" << std::endl;
len = 3;
for(auto i : range(len)){
std::cout << i << std::endl;
}
std::cout << "start stop" << std::endl;
size_t start = 1;
for(auto i : range(start, len)){
std::cout << i << std::endl;
}
std::cout << "start stop skip" << std::endl;
len = 10;
size_t skip = 3;
for(auto i : range(start, len, skip)){
std::cout << i << std::endl;
}
// invalid ranges:
std::cout << "Should not print anything after this line until exception\n";
for (auto i : range(-10, 0, -1)) {
std::cout << i << std::endl;
}
for (auto i : range(0, 1, -1)) {
std::cout << i << std::endl;
}
std::cout << "Should see exception now\n";
for (auto i : range(0, 10, 0) ) {
std::cout << i << std::endl;
}
return 0;
}