38 using lumiera::error::LUMIERA_ERROR_ASSERTION;
50 const uint REPEAT = 40;
51 const uint RAND_RANGE = 100;
52 const uint RAND_DENOM = 3;
53 const uint TIMING_CNT = 10000000;
58 double arbitrary = (1 + rand() % RAND_RANGE);
59 arbitrary /= (1 + rand() % RAND_DENOM);
61 static double prevVal;
62 if (arbitrary != prevVal)
94 sideeffectSum (TestDigxel* digxel,
double val)
97 digxel->setValueRaw (val);
100 double preval(0), newval(0);
103 protocollingMutator (TestDigxel* digxel,
double val)
107 digxel->setValueRaw (val);
111 limitingMutator (TestDigxel* digxel,
double value2set)
113 digxel->setValueRaw ((+1 < value2set) ? +1.0
114 : (-1 > value2set) ? -1.0
119 trivialMutator (TestDigxel* digxel,
double value2set)
121 digxel->setValueRaw (value2set);
125 emptyMutator (TestDigxel*,
double)
155 verifyMutatorInfluence();
156 verifyAssignMutatingOperators();
159 checkDisplayOverrun();
162 timingMeasurements();
171 CHECK (
"## +0.0 ##" ==
string(digi));
172 cout <<
"empty____" << digi << endl;
175 CHECK (-88.77 == digi);
176 CHECK (
"##-88.8 ##" ==
string(digi));
177 cout <<
"value____" << digi << endl;
187 digi.installMutator (sideeffectSum, digi);
191 for (uint i=0; i < REPEAT; ++i)
193 double arbitrary = randomFrac();
194 checksum += arbitrary;
198 CHECK (sum == checksum,
"divergence after adding %f in iteration %d", arbitrary, i);
199 CHECK (digi == arbitrary);
206 verifyMutatorInfluence ()
213 CHECK (12.3 == digi);
216 digi.installMutator (limitingMutator, digi);
217 CHECK (12.3 == digi);
219 CHECK (12.3 == digi);
226 CHECK (-0.678 == digi);
230 digi.setValueRaw(12.3);
231 CHECK (12.3 == digi);
244 digi.installMutator (protocollingMutator, digi);
247 CHECK ( 0.0 == preval && 12.3 == newval);
249 CHECK (12.3 == preval && 22.3 == newval);
251 CHECK (22.3 == preval && 17.3 == newval);
253 CHECK (17.3 == preval && 18.3 == newval);
255 CHECK (18.3 == preval && 19.3 == newval);
257 CHECK (19.3 == preval && 18.3 == newval);
259 CHECK (18.3 == preval && 17.3 == newval);
262 CHECK (18.3 == digi && 18.3 == val);
264 CHECK (19.3 == digi && 18.3 == val);
266 CHECK (18.3 == digi && 18.3 == val);
268 CHECK (17.3 == digi && 18.3 == val);
280 double someValue = d1 + randomFrac();
283 CHECK (d1 == someValue);
302 double someValue = randomFrac();
305 CHECK (d1 == someValue);
308 CHECK (d2 == someValue);
309 CHECK (!isSameObject (d1, d2));
313 CHECK (d2 == someValue);
323 digi = 123456789.12345678;
327 VERIFY_ERROR (ASSERTION, formatted = digi.show() ); // should trigger assertion 328 formatted = digi.show();
331 CHECK (formatted.length() <= digi.maxlen());
350 clock_t start(0), stop(0);
351 util::_Fmt resultDisplay(
"timings(%s)%|36T.|%4.0fns\n");
353 #define START_TIMINGS start=clock(); 354 #define DISPLAY_TIMINGS(ID)\ 356 uint ID = stop-start;\ 357 cout << resultDisplay % STRINGIFY (ID) % (double(ID)/CLOCKS_PER_SEC/TIMING_CNT*1e9) ; 361 for (uint i=0; i < TIMING_CNT; ++i)
365 DISPLAY_TIMINGS (empty_loop)
369 for (uint i=0; i < TIMING_CNT; ++i)
374 DISPLAY_TIMINGS (without_reformatting)
378 for (uint i=0; i < TIMING_CNT; ++i)
382 DISPLAY_TIMINGS (with_reformatting)
385 digi.installMutator (emptyMutator, digi);
388 for (uint i=0; i < TIMING_CNT; ++i)
392 DISPLAY_TIMINGS (with_empty_mutator)
395 digi.installMutator (trivialMutator, digi);
398 for (uint i=0; i < TIMING_CNT; ++i)
402 DISPLAY_TIMINGS (with_trivial_mutator)
405 digi.installMutator (&TestDigxel::setValueRaw, digi);
408 for (uint i=0; i < TIMING_CNT; ++i)
412 DISPLAY_TIMINGS (with_memfun_mutator)
415 CHECK (without_reformatting < with_reformatting);
A self-contained numeric element for building structured numeric displays.
Common functions for handling of time values.
A front-end for using printf-style formatting.
void verifyAssignMutatingOperators()
Implementation namespace for support and library code.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A number element for building structured numeric displays.
A collection of frequently used helper functions to support unit testing.
void timingMeasurements()
void checkDisplayOverrun()
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.