-
Notifications
You must be signed in to change notification settings - Fork 1
/
range_main.cc
92 lines (79 loc) · 2.13 KB
/
range_main.cc
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
84
85
86
87
88
89
90
91
#include <oyoung/range.hpp>
#include <gtest/gtest.h>
TEST(oyoung_range, range_9) {
auto n {0};
for(auto i: oyoung::range(9)) {
EXPECT_LT(i, 9);
EXPECT_GE(i, 0);
EXPECT_EQ(n++, i);
}
}
TEST(oyoung_range, range_1_to_10) {
auto n {1};
for(auto i: oyoung::range(1, 10)) {
EXPECT_GE(i, 1);
EXPECT_LT(i, 10);
EXPECT_EQ(n++, i);
}
}
TEST(oyoung_range, range_except_for_step_0) {
EXPECT_NO_THROW(oyoung::range(0, 10));
EXPECT_ANY_THROW(oyoung::range(0, 10, 0));
}
TEST(oyoung_range, range_20_downto_10) {
auto n {20};
for(auto i: oyoung::range(20, 10)) {
EXPECT_LE(i, 20);
EXPECT_GT(i, 10);
EXPECT_EQ(n--, i);
}
}
TEST(oyoung_range, range_1_to_10_step_3) {
auto n {1};
for(auto i: oyoung::range(1, 10, 3)) {
EXPECT_GE(i, 1);
EXPECT_LT(i, 10);
EXPECT_EQ(n, i);
n += 3;
}
}
TEST(oyoung_range, range_20_downto_10_step_2) {
auto n {20};
for(auto i: oyoung::range(20, 10, 2)) {
EXPECT_EQ(n, i);
EXPECT_GT(i, 10);
EXPECT_LE(i, 20);
n -= 2;
}
}
TEST(oyoung_range, repeat_5_with_index) {
auto n {0};
repeat(5) [&](int i) {
EXPECT_GE(i, 0);
EXPECT_LT(i, 5);
EXPECT_EQ(n++, i);
};
}
TEST(oyoung_range, repeat_3_without_index) {
auto n {0};
repeat(3) [&] {
EXPECT_GE(n, 0);
EXPECT_LT(n++, 3);
};
}
TEST(oyoung_range, repeater_6_with_index) {
auto n {0};
oyoung::Repeater(6) << [&](int i) {
EXPECT_GE(i, 0);
EXPECT_LT(i, 6);
EXPECT_EQ(n++, i);
};
}
TEST(oyoung_range, contains) {
EXPECT_TRUE(oyoung::range(5).contains(3)) << " for range(5) contains 3";
EXPECT_FALSE(oyoung::range(3).contains(5)) << " for range(3) not contains 5";
EXPECT_TRUE(oyoung::range(5, 9).contains(5)) << " for range(5, 9) contains 5";
EXPECT_FALSE(oyoung::range(5, 9).contains(9)) << " for range(5, 9) contains 9";
EXPECT_TRUE(oyoung::range(1, 100, 7).contains(8)) << " for range(5, 9) contains 5";
EXPECT_FALSE(oyoung::range(1, 100, 7).contains(9)) << " for range(5, 9) contains 9";
}