34 #include <boost/lexical_cast.hpp> 37 using boost::lexical_cast;
41 using LERR_(BOTTOM_VALUE);
57 random_or_get (Arg arg)
60 return 1 + (rand() % 10000);
62 return lexical_cast<gavl_time_t> (arg[1]);
75 verify_invalidFramerateProtection();
79 compareTimeSpan (
Time(ref));
80 relateTimeIntervals (ref);
81 verify_extremeValues();
82 verify_fractionalOffset();
100 CHECK (zero == zero);
101 CHECK (zero <= zero);
102 CHECK (zero >= zero);
137 CHECK (zero == (var - 2*(org + two)) );
140 CHECK (var == 2*two + org + org);
144 CHECK (zero == (var - org));
149 CHECK (var > Time::MIN);
151 gavl_time_t raw (var);
153 CHECK (raw > org - two);
156 CHECK (zero == -var + var);
157 CHECK (zero != -var);
180 CHECK (0.5 == boost::rational_cast<double> (halve));
191 CHECK (
"1:01:01.001" ==
string(tx3));
196 CHECK (((t1-th)*=2) == t1);
210 CHECK (0 == hashFunc (Time::ZERO));
211 size_t hh =
sizeof(size_t)*CHAR_BIT/2;
212 CHECK (
size_t(1)<<hh == hashFunc (
TimeValue{1}));
213 CHECK (
size_t(1) == hashFunc (
TimeValue(
size_t(1)<<hh)));
215 size_t h1 = hashFunc (org);
218 CHECK (h1 > 0 || org == Time::ZERO);
219 CHECK (h2 - h1 ==
size_t(1)<<hh);
220 CHECK (h3 ==
size_t(_raw(org)));
225 verify_invalidFramerateProtection()
233 CHECK (FrameRate::approx(2000) ==
"2000FPS"_expect);
234 CHECK (FrameRate::approx(1e05) ==
"100000FPS"_expect);
235 CHECK (FrameRate::approx(1e06) ==
"1000000FPS"_expect);
236 CHECK (FrameRate::approx(1e12) ==
"4194303FPS"_expect);
237 CHECK (FrameRate::approx(1e14) ==
"4194303FPS"_expect);
238 CHECK (FrameRate::approx(1e-5) ==
"14/1398101FPS"_expect);
239 CHECK (FrameRate::approx(1e-6) ==
"4/4194303FPS"_expect);
240 CHECK (FrameRate::approx(1e-7) ==
"1/4194303FPS"_expect);
241 CHECK (FrameRate::approx(1e-9) ==
"1/4194303FPS"_expect);
243 CHECK (
FrameRate( 20
'000, Duration{Time{0,10}}) == "2000FPS"_expect); // exact 269 Offset reverse(point,org);
270 CHECK (reverse < off5);
271 CHECK (reverse.
abs() == off5);
273 CHECK (0 == off5 + reverse);
279 CHECK (7 == -2*off9 + off5*5);
298 Offset backwards(point,org);
299 CHECK (backwards < zero);
302 CHECK (distance > zero);
303 CHECK (distance == backwards.
abs());
306 CHECK (len1 ==
Time(
FSecs(23,1000)) +
Time(0, 4 + 5*60 + 6*3600));
313 CHECK (
Time(0,2,0,0) == unit);
316 CHECK (FrameRate::NTSC.duration() ==
Time(
FSecs(1001,30000)));
317 cout <<
"NTSC-Framerate = " << FrameRate::NTSC.asDouble() << endl;
325 CHECK (point < zero);
326 CHECK (point < backwards);
328 CHECK (distance + point < zero);
329 CHECK (distance == backwards.
abs());
334 verify_extremeValues()
337 CHECK (_raw(
Time::MAX) < std::numeric_limits<int64_t>::max());
338 CHECK (_raw(Time::MIN) > std::numeric_limits<int64_t>::min());
347 CHECK (outlier < Time::MIN);
350 CHECK (_raw(
Duration::MAX) < std::numeric_limits<int64_t>::max());
366 CHECK (
TimeSpan(outlier, Duration::MAX).conform() ==
TimeSpan(Time::MIN,Duration::MAX));
375 verify_fractionalOffset()
377 typedef boost::rational<FrameCnt> Frac;
381 Offset o1 = Frac(1,2) * three;
382 CHECK (o1 > Time::ZERO);
385 Offset o2 = -Frac(1,2) * three;
386 CHECK (o2 < Time::ZERO);
389 CHECK (three * Frac(1,2) * 2 != three);
390 CHECK (three *(Frac(1,2) * 2) == three);
404 CHECK (org == interval);
408 CHECK (theLength ==
Offset(org,five).abs());
410 Time endpoint = interval.end();
413 CHECK (
Offset(interval,endpoint) ==
Offset(org,five).abs());
416 cout <<
"Interval-1: " << interval
417 <<
" Interval-2: " << successor
418 <<
" End point: " << successor.end()
424 compareTimeSpan (
Time const& org)
431 CHECK (span1 == span2);
432 CHECK (span2 == span1);
433 CHECK (span3 == span4);
434 CHECK (span4 == span3);
436 CHECK (span1 != span3);
437 CHECK (span3 != span1);
438 CHECK (span1 != span4);
439 CHECK (span4 != span1);
440 CHECK (span2 != span3);
441 CHECK (span3 != span2);
442 CHECK (span2 != span4);
443 CHECK (span4 != span2);
446 CHECK (span1.end() == span2.end());
447 CHECK (span3.end() == span4.end());
454 CHECK (span1 != span1x);
455 CHECK (span3 != span3y);
456 CHECK (span3 != span3z);
458 CHECK ( span1 < span1x);
459 CHECK ( span1 <= span1x);
460 CHECK (!(span1 > span1x));
461 CHECK (!(span1 >= span1x));
463 CHECK ( span3 > span3y);
464 CHECK ( span3 >= span3y);
465 CHECK (!(span3 < span3y));
466 CHECK (!(span3 <= span3y));
468 CHECK ( span3 < span3z);
469 CHECK ( span3y < span3z);
473 CHECK (span1 < span1x);
474 CHECK (span1.duration() == span1x.duration());
475 CHECK (span1.start() < span1x.start());
476 CHECK (span1.end() < span1x.end());
478 CHECK (span3 > span3y);
479 CHECK (span3.duration() > span3y.duration());
480 CHECK (span3.start() == span3y.start());
481 CHECK (span3.end() > span3y.end());
482 CHECK (
Time(span3) ==
Time(span3y));
484 CHECK (span3 < span3z);
485 CHECK (span3.duration() > span3z.duration());
486 CHECK (span3.start() < span3z.start());
487 CHECK (span3.end() != span3z.end());
490 CHECK (span3y < span3z);
491 CHECK (span3y.duration() == span3z.duration());
492 CHECK (span3y.start() < span3z.start());
493 CHECK (span3y.end() < span3z.end());
507 CHECK ( span1.contains(probe));
508 CHECK (!span2.contains(probe));
511 CHECK ( span1.contains(probe));
512 CHECK ( span2.contains(probe));
515 CHECK (!span1.contains(probe));
516 CHECK ( span2.contains(probe));
519 CHECK (!span1.contains(probe));
520 CHECK (!span2.contains(probe));
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
static const Duration MAX
maximum possible temporal extension
Framerate specified as frames per second.
static const gavl_time_t SCALE
Number of micro ticks (µs) per second as basic time scale.
Primary class template for std::hash.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
void checkTimeConvenience(TimeValue org)
static const Duration NIL
constant to indicate "no duration"
Implementation namespace for support and library code.
Lumiera's internal time value datatype.
void checkTimeHash(TimeValue org)
Simple test class runner.
Duration abs() const
interpret the distance given by this offset as a time duration
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
boost::rational< int64_t > FSecs
rational representation of fractional seconds
A collection of frequently used helper functions to support unit testing.
void checkBasicTimeValues(TimeValue org)
ExampleStrategy::Qualifier two(string additionalArg)
definition of another qualifier two(arg), accepting an additional argument
Offset measures a distance in time.
Duration is the internal Lumiera time metric.
A time interval anchored at a specific point in time.
ExampleStrategy::Qualifier one()
definition of a qualifier one()
a family of time value like entities and their relationships.
basic constant internal time value.
void checkMutableTime(TimeValue org)
static const FrameRate PAL
predefined constant for PAL framerate