-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.cpp
More file actions
221 lines (186 loc) · 5.09 KB
/
Copy pathtests.cpp
File metadata and controls
221 lines (186 loc) · 5.09 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include <iostream>
#include <sstream>
#include "time_span.h"
using namespace std;
bool CheckValues(TimeSpan time, int hours, int minutes, int seconds) {
if ((time.hours() != hours) || (time.minutes() != minutes) ||
(time.seconds() != seconds)) {
return false;
}
return true;
}
bool TestToSeconds() {
TimeSpan ts(1, 2, 3);
return ts.ToSeconds() == 3723;
}
bool TestLessThan() {
TimeSpan ts1(1, 2, 3);
TimeSpan ts2(2, 3, 4);
return ts1 < ts2;
}
bool TestLessThanOrEqual() {
TimeSpan ts1(1, 2, 3);
TimeSpan ts2(1, 2, 3);
return ts1 <= ts2;
}
bool TestGreaterThan() {
TimeSpan ts1(1, 2, 3);
TimeSpan ts2(2, 3, 4);
return ts2 > ts1;
}
bool TestGreaterThanOrEqual() {
TimeSpan ts1(2, 3, 4);
TimeSpan ts2(2, 3, 4);
return ts2 >= ts1;
}
bool TestEqual() {
TimeSpan ts1(2, 3, 4);
TimeSpan ts2(2, 3, 4);
return ts1 == ts2;
}
bool TestNotEqual() {
TimeSpan ts1(2, 3, 5);
TimeSpan ts2(2, 3, 4);
return ts1 != ts2;
}
bool TestNegation() {
TimeSpan ts(1, 2, 3);
ts = -ts;
return CheckValues(ts, -1, -2, -3);
}
bool TestLargeValues() {
TimeSpan ts1(1000, 120, 180);
return CheckValues(ts1, 1002, 3, 0);
}
bool TestCombineAddSubtract() {
TimeSpan ts1(10, 30, 45);
TimeSpan ts2(2, 15, 30);
TimeSpan ts3 = ts1 + ts2 - ts1;
return CheckValues(ts3, 2, 15, 30);
}
bool TestChainedOperations() {
TimeSpan ts1(5, 10, 15);
TimeSpan ts2(1, 2, 3);
TimeSpan ts3 = ts1 + ts2 - ts2 + ts1;
return CheckValues(ts3, 10, 20, 30);
}
bool TestZeros() {
TimeSpan ts(0, 0, 0);
return CheckValues(ts, 0, 0, 0);
}
bool TestFloatSeconds() {
TimeSpan ts(127.86);
return CheckValues(ts, 0, 2, 8);
}
bool TestNegativeSecond() {
TimeSpan ts(1.5, 4, -10);
if (!CheckValues(ts, 1, 33, 50)) {
return false;
}
ts = TimeSpan(7, -3);
if (!CheckValues(ts, 0, 6, 57)) {
return false;
}
ts = TimeSpan(-190);
if (!CheckValues(ts, 0, -3, -10)) {
return false;
}
return true;
}
bool TestNegativeMinute() {
TimeSpan ts(8, -23, 0);
if (!CheckValues(ts, 7, 37, 0)) {
return false;
}
return true;
}
bool TestNegativeHour() {
TimeSpan ts(-3, 73, 2);
return CheckValues(ts, -1, -46, -58);
}
bool TestAdd() {
TimeSpan ts1, ts2(5), ts3(7, 0), ts4(4, 0, 0);
TimeSpan add_it_up = ts1 + ts2 + ts3 + ts4;
return CheckValues(add_it_up, 4, 7, 5);
}
bool TestSubtract() {
TimeSpan ts1, ts2(5), ts3(7, 0), ts4(4, 0, 0);
TimeSpan subtract_it_up = ts4 - ts3 - ts2 - ts1;
return CheckValues(subtract_it_up, 3, 52, 55);
}
bool TestAddInPlace() {
TimeSpan ts1(5, 6, 7);
TimeSpan ts2(1, 1, 1);
if ((!CheckValues(ts1, 5, 6, 7)) || (!CheckValues(ts2, 1, 1, 1))) {
return false;
}
ts1 += ts2;
if ((!CheckValues(ts1, 6, 7, 8)) || (!CheckValues(ts2, 1, 1, 1))) {
return false;
}
return true;
}
bool TestSubtractInPlace() {
TimeSpan ts1(5, 6, 7);
TimeSpan ts2(1, 1, 1);
if ((!CheckValues(ts1, 5, 6, 7)) || (!CheckValues(ts2, 1, 1, 1))) {
return false;
}
ts1 -= ts2;
if ((!CheckValues(ts1, 4, 5, 6)) || (!CheckValues(ts2, 1, 1, 1))) {
return false;
}
return true;
}
bool TestInputStream() {
stringstream input_stream("2 3 4");
TimeSpan ts;
input_stream >> ts;
return CheckValues(ts, 2, 3, 4);
}
int main() {
cout << "Testing TimeSpan Class" << endl;
if (!TestToSeconds())
cout << "Failed: TestToSeconds" << endl;
if (!TestLessThan())
cout << "Failed: TestLessThan" << endl;
if (!TestLessThanOrEqual())
cout << "Failed: TestLessThanOrEqual" << endl;
if (!TestGreaterThan())
cout << "Failed: TestGreaterThan" << endl;
if (!TestGreaterThanOrEqual())
cout << "Failed: TestGreaterThanOrEqual" << endl;
if (!TestEqual())
cout << "Failed: TestEqual" << endl;
if (!TestNotEqual())
cout << "Failed: TestNotEqual" << endl;
if (!TestNegation())
cout << "Failed: TestNegation" << endl;
if (!TestLargeValues())
cout << "Failed: TestLargeValues" << endl;
if (!TestCombineAddSubtract())
cout << "Failed: TestCombineAddSubtract" << endl;
if (!TestChainedOperations())
cout << "Failed: TestChainedOperations" << endl;
if (!TestZeros())
cout << "Failed: TestZeros" << endl;
if (!TestFloatSeconds())
cout << "Failed: TestFloatSeconds" << endl;
if (!TestNegativeSecond())
cout << "Failed: TestNegativeSecond" << endl;
if (!TestNegativeMinute())
cout << "Failed: TestNegativeMinute" << endl;
if (!TestNegativeHour())
cout << "Failed: TestNegativeHour" << endl;
if (!TestAdd())
cout << "Failed: TestAdd" << endl;
if (!TestAddInPlace())
cout << "Failed: TestAddInPlace" << endl;
if (!TestSubtract())
cout << "Failed: TestSubtract" << endl;
if (!TestSubtractInPlace())
cout << "Failed: TestSubtractInPlace" << endl;
if (!TestInputStream())
cout << "Failed: TestInputStream" << endl;
cout << "Testing Complete" << endl;
}