comparison base/test/TestRealTime.h @ 1015:30afdc7c7b89

Couple more RealTime tests
author Chris Cannam
date Thu, 20 Nov 2014 12:30:16 +0000
parents ace22dccde8f
children abe13fe10ed6
comparison
equal deleted inserted replaced
1014:ace22dccde8f 1015:30afdc7c7b89
48 QCOMPARE(RealTime(0, 0), RealTime(0, 0)); 48 QCOMPARE(RealTime(0, 0), RealTime(0, 0));
49 49
50 // wraparounds 50 // wraparounds
51 QCOMPARE(RealTime(0, ONE_BILLION/2), RealTime(1, -ONE_BILLION/2)); 51 QCOMPARE(RealTime(0, ONE_BILLION/2), RealTime(1, -ONE_BILLION/2));
52 QCOMPARE(RealTime(0, -ONE_BILLION/2), RealTime(-1, ONE_BILLION/2)); 52 QCOMPARE(RealTime(0, -ONE_BILLION/2), RealTime(-1, ONE_BILLION/2));
53
54 QCOMPARE(RealTime(1, ONE_BILLION), RealTime(2, 0));
55 QCOMPARE(RealTime(1, -ONE_BILLION), RealTime(0, 0));
56 QCOMPARE(RealTime(-1, ONE_BILLION), RealTime(0, 0));
57 QCOMPARE(RealTime(-1, -ONE_BILLION), RealTime(-2, 0));
53 58
54 QCOMPARE(RealTime(2, -ONE_BILLION*2), RealTime(0, 0)); 59 QCOMPARE(RealTime(2, -ONE_BILLION*2), RealTime(0, 0));
55 QCOMPARE(RealTime(2, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2)); 60 QCOMPARE(RealTime(2, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2));
56 61
57 QCOMPARE(RealTime(-2, ONE_BILLION*2), RealTime(0, 0)); 62 QCOMPARE(RealTime(-2, ONE_BILLION*2), RealTime(0, 0));
65 QCOMPARE(RealTime(1, -1).nsec, ONE_BILLION-1); 70 QCOMPARE(RealTime(1, -1).nsec, ONE_BILLION-1);
66 QCOMPARE(RealTime(-1, 1).sec, 0); 71 QCOMPARE(RealTime(-1, 1).sec, 0);
67 QCOMPARE(RealTime(-1, 1).nsec, -ONE_BILLION+1); 72 QCOMPARE(RealTime(-1, 1).nsec, -ONE_BILLION+1);
68 QCOMPARE(RealTime(-1, -1).sec, -1); 73 QCOMPARE(RealTime(-1, -1).sec, -1);
69 QCOMPARE(RealTime(-1, -1).nsec, -1); 74 QCOMPARE(RealTime(-1, -1).nsec, -1);
75
76 QCOMPARE(RealTime(2, -ONE_BILLION*2).sec, 0);
77 QCOMPARE(RealTime(2, -ONE_BILLION*2).nsec, 0);
78 QCOMPARE(RealTime(2, -ONE_BILLION/2).sec, 1);
79 QCOMPARE(RealTime(2, -ONE_BILLION/2).nsec, ONE_BILLION/2);
80
81 QCOMPARE(RealTime(-2, ONE_BILLION*2).sec, 0);
82 QCOMPARE(RealTime(-2, ONE_BILLION*2).nsec, 0);
83 QCOMPARE(RealTime(-2, ONE_BILLION/2).sec, -1);
84 QCOMPARE(RealTime(-2, ONE_BILLION/2).nsec, -ONE_BILLION/2);
70 } 85 }
71 86
72 void fromSeconds() 87 void fromSeconds()
73 { 88 {
74 QCOMPARE(RealTime::fromSeconds(0), RealTime(0, 0)); 89 QCOMPARE(RealTime::fromSeconds(0), RealTime(0, 0));
205 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(2, ONE_BILLION/2)); 220 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(2, ONE_BILLION/2));
206 221
207 QCOMPARE(RealTime(0, ONE_BILLION/2) - RealTime(-1, 0), RealTime(1, ONE_BILLION/2)); 222 QCOMPARE(RealTime(0, ONE_BILLION/2) - RealTime(-1, 0), RealTime(1, ONE_BILLION/2));
208 QCOMPARE(RealTime(0, -ONE_BILLION/2) - RealTime(1, 0), RealTime(-1, -ONE_BILLION/2)); 223 QCOMPARE(RealTime(0, -ONE_BILLION/2) - RealTime(1, 0), RealTime(-1, -ONE_BILLION/2));
209 } 224 }
225
226 void negate()
227 {
228 QCOMPARE(-RealTime(0, 0), RealTime(0, 0));
229 QCOMPARE(-RealTime(1, 0), RealTime(-1, 0));
230 QCOMPARE(-RealTime(1, ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2));
231 QCOMPARE(-RealTime(-1, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2));
232 }
233
234 void compare()
235 {
236 int sec, nsec;
237 for (sec = -2; sec <= 2; sec += 2) {
238 for (nsec = -1; nsec <= 1; nsec += 1) {
239 QCOMPARE(RealTime(sec, nsec) < RealTime(sec, nsec), false);
240 QCOMPARE(RealTime(sec, nsec) > RealTime(sec, nsec), false);
241 QCOMPARE(RealTime(sec, nsec) == RealTime(sec, nsec), true);
242 QCOMPARE(RealTime(sec, nsec) != RealTime(sec, nsec), false);
243 QCOMPARE(RealTime(sec, nsec) <= RealTime(sec, nsec), true);
244 QCOMPARE(RealTime(sec, nsec) >= RealTime(sec, nsec), true);
245 }
246 }
247 RealTime prev(-3, 0);
248 for (sec = -2; sec <= 2; sec += 2) {
249 for (nsec = -1; nsec <= 1; nsec += 1) {
250
251 RealTime curr(sec, nsec);
252
253 QCOMPARE(prev < curr, true);
254 QCOMPARE(prev > curr, false);
255 QCOMPARE(prev == curr, false);
256 QCOMPARE(prev != curr, true);
257 QCOMPARE(prev <= curr, true);
258 QCOMPARE(prev >= curr, false);
259
260 QCOMPARE(curr < prev, false);
261 QCOMPARE(curr > prev, true);
262 QCOMPARE(curr == prev, false);
263 QCOMPARE(curr != prev, true);
264 QCOMPARE(curr <= prev, false);
265 QCOMPARE(curr >= prev, true);
266
267 prev = curr;
268 }
269 }
270 }
271
272
273
210 }; 274 };
211 275
212 #endif 276 #endif