27 using lumiera::error::LUMIERA_ERROR_ASSERTION;
39 const uint REPEAT = 40;
40 const uint RAND_RANGE = 100;
41 const uint RAND_DENOM = 3;
42 const uint TIMING_CNT = 10000000;
47 double arbitrary = 1 +
rani(RAND_RANGE);
48 arbitrary /= 1 +
rani(RAND_DENOM);
50 static double prevVal;
51 if (arbitrary != prevVal)
83 sideeffectSum (TestDigxel* digxel,
double val)
86 digxel->setValueRaw (val);
89 double preval(0), newval(0);
92 protocollingMutator (TestDigxel* digxel,
double val)
96 digxel->setValueRaw (val);
100 limitingMutator (TestDigxel* digxel,
double value2set)
102 digxel->setValueRaw ((+1 < value2set) ? +1.0
103 : (-1 > value2set) ? -1.0
108 trivialMutator (TestDigxel* digxel,
double value2set)
110 digxel->setValueRaw (value2set);
114 emptyMutator (TestDigxel*,
double)
146 verifyMutatorInfluence();
147 verifyAssignMutatingOperators();
150 checkDisplayOverrun();
153 timingMeasurements();
162 CHECK (
"## +0.0 ##" ==
string(digi));
163 cout <<
"empty____" << digi << endl;
166 CHECK (-88.77 == digi);
167 CHECK (
"##-88.8 ##" ==
string(digi));
168 cout <<
"value____" << digi << endl;
178 digi.installMutator (sideeffectSum, digi);
182 for (uint i=0; i < REPEAT; ++i)
184 double arbitrary = randomFrac();
185 checksum += arbitrary;
189 CHECK (sum == checksum,
"divergence after adding %f in iteration %d", arbitrary, i);
190 CHECK (digi == arbitrary);
197 verifyMutatorInfluence ()
204 CHECK (12.3 == digi);
207 digi.installMutator (limitingMutator, digi);
208 CHECK (12.3 == digi);
210 CHECK (12.3 == digi);
217 CHECK (-0.678 == digi);
221 digi.setValueRaw(12.3);
222 CHECK (12.3 == digi);
235 digi.installMutator (protocollingMutator, digi);
238 CHECK ( 0.0 == preval && 12.3 == newval);
240 CHECK (12.3 == preval && 22.3 == newval);
242 CHECK (22.3 == preval && 17.3 == newval);
244 CHECK (17.3 == preval && 18.3 == newval);
246 CHECK (18.3 == preval && 19.3 == newval);
248 CHECK (19.3 == preval && 18.3 == newval);
250 CHECK (18.3 == preval && 17.3 == newval);
253 CHECK (18.3 == digi && 18.3 == val);
255 CHECK (19.3 == digi && 18.3 == val);
257 CHECK (18.3 == digi && 18.3 == val);
259 CHECK (17.3 == digi && 18.3 == val);
271 double someValue = d1 + randomFrac();
274 CHECK (d1 == someValue);
293 double someValue = randomFrac();
296 CHECK (d1 == someValue);
299 CHECK (d2 == someValue);
300 CHECK (not isSameObject (d1, d2));
304 CHECK (d2 == someValue);
314 digi = 123456789.12345678;
318 VERIFY_ERROR (ASSERTION, formatted = digi.show() ); // should trigger assertion 319 formatted = digi.show();
322 CHECK (formatted.length() <= digi.maxlen());
341 clock_t start(0), stop(0);
342 util::_Fmt resultDisplay(
"timings(%s)%|36T.|%4.0fns\n");
344 #define START_TIMINGS start=clock(); 345 #define DISPLAY_TIMINGS(ID)\ 347 uint ID = stop-start;\ 348 cout << resultDisplay % STRINGIFY (ID) % (double(ID)/CLOCKS_PER_SEC/TIMING_CNT*1e9) ; 352 for (uint i=0; i < TIMING_CNT; ++i)
356 DISPLAY_TIMINGS (empty_loop)
360 for (uint i=0; i < TIMING_CNT; ++i)
365 DISPLAY_TIMINGS (without_reformatting)
369 for (uint i=0; i < TIMING_CNT; ++i)
373 DISPLAY_TIMINGS (with_reformatting)
376 digi.installMutator (emptyMutator, digi);
379 for (uint i=0; i < TIMING_CNT; ++i)
383 DISPLAY_TIMINGS (with_empty_mutator)
386 digi.installMutator (trivialMutator, digi);
389 for (uint i=0; i < TIMING_CNT; ++i)
393 DISPLAY_TIMINGS (with_trivial_mutator)
396 digi.installMutator (&TestDigxel::setValueRaw, digi);
399 for (uint i=0; i < TIMING_CNT; ++i)
403 DISPLAY_TIMINGS (with_memfun_mutator)
406 CHECK (without_reformatting < with_reformatting);
A self-contained numeric element for building structured numeric displays.
int rani(uint bound=_iBOUND())
A front-end for using printf-style formatting.
void verifyAssignMutatingOperators()
Implementation namespace for support and library code.
Simplistic 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()
Generating (pseudo) random numbers with controlled seed.
void checkDisplayOverrun()
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities. ...