Lumiera  0.pre.03
»edit your freedom«
time-basics-test.cpp
Go to the documentation of this file.
1 /*
2  TimeBasics(Test) - working with Lumiera's internal Time values
3 
4  Copyright (C)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/time/timevalue.hpp"
21 #include "lib/time/diagnostics.hpp"
22 #include "lib/format-cout.hpp"
23 #include "lib/random.hpp"
24 #include "lib/util.hpp"
25 
26 #include <boost/lexical_cast.hpp>
27 
28 using boost::lexical_cast;
29 using util::isnil;
30 
31 
32 namespace lib {
33 namespace test{
34 
35  using time::Time;
36  using time::TimeVar;
37  using time::FSecs;
38 
39 
40  /****************************************/
43  class TimeBasics_test : public Test
44  {
45  virtual void
46  run (Arg arg)
47  {
48  FSecs refval = isnil(arg)? 1 : lexical_cast<long> (arg[1]);
49 
50  Time org(refval);
51 
52  checkBasics (org);
53  checkComparisons (org);
54  checkComponentDiagnostics();
55  }
56 
57 
58  void
59  checkBasics (Time const& ref)
60  {
61  Time zero;
62  Time two (FSecs(2));
63  Time max (Time::MAX);
64  Time min (Time::MIN);
65 
66  TimeVar var (ref);
67 
68  var += two;
69  var *= 2;
70  CHECK (zero == (var - 2*(ref + two)) );
71 
72  var = ref;
73  CHECK (zero == (var - ref));
74  }
75 
76 
77  void
78  checkComparisons (Time const& ref)
79  {
80  Time zero;
81  Time max (Time::MAX);
82  Time min (Time::MIN);
83 
84  CHECK (zero == Time());
85  CHECK (min < zero);
86  CHECK (max > zero);
87 
88  TimeVar var (ref);
89  CHECK ( (var == ref) );
90  CHECK (!(var != ref) );
91  CHECK ( (var >= ref) );
92  CHECK ( (var <= ref) );
93  CHECK (!(var < ref) );
94  CHECK (!(var > ref) );
95 
96  var += Time(FSecs(2));
97  CHECK (!(var == ref) );
98  CHECK ( (var != ref) );
99  CHECK ( (var >= ref) );
100  CHECK (!(var <= ref) );
101  CHECK (!(var < ref) );
102  CHECK ( (var > ref) );
103 
104  gavl_time_t gat(var);
105  CHECK (!(gat == ref) );
106  CHECK ( (gat != ref) );
107  CHECK ( (gat >= ref) );
108  CHECK (!(gat <= ref) );
109  CHECK (!(gat < ref) );
110  CHECK ( (gat > ref) );
111 
112  CHECK ( (var == gat) );
113  CHECK (!(var != gat) );
114  CHECK ( (var >= gat) );
115  CHECK ( (var <= gat) );
116  CHECK (!(var < gat) );
117  CHECK (!(var > gat) );
118  }
119 
120 
121  void
122  checkComponentDiagnostics()
123  {
124  seedRand();
125  int millis = rani(1000);
126  int secs = rani (60);
127  int mins = rani (60);
128  int hours = rani (100);
129 
130  Time time(millis,secs,mins,hours);
131  CHECK (Time() < time);
132  CHECK (millis == getMillis(time));
133  CHECK (secs == getSecs (time));
134  CHECK (mins == getMins (time));
135  CHECK (hours == getHours (time));
136  cout << time << endl;
137 
138  Time t2(2008,0);
139  cout << t2 << endl;
140  CHECK ( 8 == getMillis(t2));
141  CHECK ( 2 == getSecs (t2));
142  CHECK ( 0 == getMins (t2));
143  CHECK ( 0 == getHours (t2));
144 
145  Time t3(2008,88);
146  cout << t3 << endl;
147  CHECK ( 8 == getMillis(t3));
148  CHECK (30 == getSecs (t3));
149  CHECK ( 1 == getMins (t3));
150  CHECK ( 0 == getHours (t3));
151 
152  Time t4(2008,118,58);
153  cout << t4 << endl;
154  CHECK ( 8 == getMillis(t4));
155  CHECK ( 0 == getSecs (t4));
156  CHECK ( 0 == getMins (t4));
157  CHECK ( 1 == getHours (t4));
158  }
159  };
160 
161 
163  LAUNCHER (TimeBasics_test, "unit common");
164 
165 
166 
167 }} // namespace lib::test
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:232
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:40
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
Extension to the lib::time::Time wrapper, adding output and further diagnostic aids.
Implementation namespace for support and library code.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
Simplistic test class runner.
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
Definition: timevalue.hpp:220
ExampleStrategy::Qualifier two(string additionalArg)
definition of another qualifier two(arg), accepting an additional argument
Generating (pseudo) random numbers with controlled seed.
a family of time value like entities and their relationships.
static const Time MAX
Definition: timevalue.hpp:309