-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
PRange_unittest.cc
115 lines (104 loc) · 2.48 KB
/
PRange_unittest.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <cmath>
#include <gtest/gtest.h>
#include <shogun/base/progress.h>
#include <shogun/io/SGIO.h>
#include <thread>
using namespace shogun;
SGIO range_io;
const int millis = 10;
auto range_test = progress(range(0, 100), range_io);
TEST(PRange, basic_upper)
{
int other_i = 0;
int count = 10;
for (auto i : progress(range(count), range_io))
{
EXPECT_EQ(i, other_i);
other_i++;
}
EXPECT_EQ(count, other_i);
}
TEST(PRange, basic_lower_upper)
{
int count = 10;
int start = std::rand();
int other_i = start;
for (auto i : progress(range(start, start + count), range_io))
{
EXPECT_EQ(i, other_i);
other_i++;
}
EXPECT_EQ(start + count, other_i);
}
TEST(PRange, zero)
{
int actual_count = 0;
int count = 0;
for (auto i : progress(range(count), range_io))
{
(void)i;
actual_count++;
}
EXPECT_EQ(count, actual_count);
}
TEST(PRange, identical_bounds)
{
int actual_count = 0;
int b = std::rand();
for (auto i : progress(range(b, b), range_io))
{
(void)i;
actual_count++;
}
EXPECT_EQ(0, actual_count);
}
TEST(PRange, progress_correct_bounds_positive)
{
range_io.enable_progress();
range_test = progress(range(0, 100), range_io);
for (auto i : range_test)
{
std::this_thread::sleep_for(std::chrono::milliseconds(millis));
EXPECT_EQ(std::ceil(range_test.get_last_progress()), i);
}
}
TEST(PRange, progress_correct_bounds_negative)
{
range_io.enable_progress();
range_test = progress(range(-100, 0), range_io);
for (auto i : range_test)
{
std::this_thread::sleep_for(std::chrono::milliseconds(millis));
EXPECT_EQ(std::ceil(range_test.get_last_progress()), (100 + i));
}
}
TEST(PRange, DISABLED_progress_incorrect_bounds_positive)
{
range_io.enable_progress();
range_test = progress(range(100, 0), range_io);
for (auto i : range_test)
{
std::this_thread::sleep_for(std::chrono::milliseconds(millis));
}
EXPECT_FLOAT_EQ(range_test.get_last_progress(), (float64_t)0);
}
TEST(PRange, DISABLED_progress_incorrect_bounds_negative)
{
range_io.enable_progress();
range_test = progress(range(100, 0), range_io);
for (auto i : range_test)
{
std::this_thread::sleep_for(std::chrono::milliseconds(millis));
}
EXPECT_FLOAT_EQ(range_test.get_last_progress(), (float64_t)0);
}
TEST(PRange, DISABLED_progress_incorrect_bounds_equal)
{
range_io.enable_progress();
range_test = progress(range(1, 1), range_io);
for (auto i : range_test)
{
std::this_thread::sleep_for(std::chrono::milliseconds(millis));
}
EXPECT_FLOAT_EQ(range_test.get_last_progress(), (float64_t)0);
}