37 #include <boost/lexical_cast.hpp> 38 #include <unordered_map> 50 using boost::lexical_cast;
61 using lumiera::error::LERR_(ITER_EXHAUST);
63 using iter_source::eachEntry;
64 using iter_source::transform;
65 using iter_source::singleVal;
66 using iter_source::eachMapKey;
67 using iter_source::eachMapVal;
68 using iter_source::eachValForKey;
69 using iter_source::eachDistinctKey;
78 typedef const char* CStr;
95 current_ = buffer_.c_str();
103 if (pos && *pos && **pos)
106 if (!(pos && *pos && **pos))
117 INFO (
test,
"created TestSource(\"%s\")", cStr(buffer_));
133 data_.push_back(num--);
136 typedef list<int>::iterator sourceIter;
139 iterator begin() {
return iterator(data_.begin(),data_.end()); }
140 iterator end() {
return iterator(); }
150 for ( ; iter; ++iter )
151 cout <<
"::" << *iter;
180 typedef std::map<string,TimeVar> TreeMap;
181 typedef std::unordered_map<string,TimeVar> HashMap;
183 typedef std::multimap<int,int> TreeMultimap;
184 typedef std::unordered_multimap<int,int>HashMultimap;
190 if (0 < arg.size()) NUM_ELMS = lexical_cast<uint> (arg[1]);
192 verify_simpleIters();
193 verify_transformIter();
195 verify_MapWrappers<TreeMap>();
196 verify_MapWrappers<HashMap>();
198 verify_MultimapIters<TreeMultimap>();
199 verify_MultimapIters<HashMultimap>();
207 WrappedList customList(NUM_ELMS);
208 TestSource dedicatedSource(NUM_ELMS);
209 list<int>& rawList(customList.data_);
211 IntIter iii (eachEntry (customList));
212 IntIter isi (eachEntry (rawList.begin(), rawList.end()));
215 CHECK (!isnil (iii));
216 CHECK (!isnil (isi));
217 CHECK (!isnil (cii));
240 WrappedList customList(NUM_ELMS);
241 WrappedList::iterator sourceValues = customList.begin();
244 auto makeTime = [](
int input_sec) ->
TimeVar 249 TimeIter tIt (transform (sourceValues, makeTime));
250 CHECK (!isnil (tIt));
262 IntIter ii = singleVal(12);
263 CHECK (not isnil(ii));
275 CHECK (not isnil(ii));
293 for (uint i=0; i<NUM_ELMS; ++i)
296 StringIter sIter = eachMapKey (testMap);
297 TimeIter tIter = eachMapVal (testMap);
299 CHECK (sIter && tIter);
303 CHECK (!sIter && !tIter);
309 StringIter justSomeKey = eachMapKey (testMap);
310 TimeIter correspondingVal = eachMapVal (testMap);
315 TimeIter value4key = eachValForKey (testMap,
"nonexistent key");
318 value4key = eachValForKey (testMap, *justSomeKey);
320 CHECK (*value4key == *correspondingVal);
328 verify_MultimapIters()
331 for (uint i=0; i<NUM_ELMS; ++i)
333 uint n = 1 + rand() % 100;
334 do testMap.insert (make_pair (i,n));
337 CHECK (NUM_ELMS < testMap.size(),
"no repetition in test data??");
339 IntIter keys = eachDistinctKey (testMap);
341 cout <<
"distinct_keys";
346 cout <<
"values_4_key";
347 IntIter vals = eachValForKey (testMap, NUM_ELMS);
350 vals = eachValForKey (testMap, 0);
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
virtual void nextResult(Pos &pos) override
iteration step: switch on to the next element.
Any copy and copy construction prohibited.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify a statement indeed raises an exception.
const char * cStr(string const &org)
convenience shortcut: conversion to c-String via string.
void verify_transformIter()
Implementation namespace for support and library code.
string randStr(size_t len)
create garbage string of given length
Lumiera's internal time value datatype.
Explicit implementation of the IterSource interface (test dummy) Creates a random string and chops of...
virtual Pos firstResult() override
iteration start: prepare the first element.
Iteration source interface to abstract a data source, which then can be accessed through IterAdapter ...
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
void pullOut(IT &iter)
diagnostics helper
boost::rational< int64_t > FSecs
rational representation of fractional seconds
A collection of frequently used helper functions to support unit testing.
void verify_singleValIter()
lib::time::Time randTime()
create a random but not insane Time value between 1s ...
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
test dummy: simply wrapping an STL container and exposing a range as Lumiera Forward Iterator ...
Extension module to build an opaque data source, accessible as Lumiera Forward Iterator.