37 #include <boost/lexical_cast.hpp> 47 using boost::lexical_cast;
53 using LERR_(ITER_EXHAUST);
68 data_.push_back(num--);
71 typedef vector<int>::iterator sourceIter;
74 iterator begin() {
return iterator(data_.begin(),data_.end()); }
75 iterator end() {
return iterator(); }
97 typedef TestSource::iterator Iter;
103 if (0 < arg.size()) NUM_ELMS = lexical_cast<uint> (arg[1]);
105 TestSource source(NUM_ELMS);
107 pullOut (source.begin());
108 verifyComparisons (source.begin());
111 buildFilterIterator (source.begin());
112 Iter ii (source.begin());
114 buildFilterIterator (ii);
115 verify_filterExtension();
116 verify_filterRepetitions();
118 buildWrappedSingleElement();
120 buildTransformingIterator (source.begin());
122 verifyPullLast(source.begin());
129 pullOut (IT
const& ii)
132 cout <<
"::" << *
iter;
138 static bool takeAll (
int) {
return true; }
139 static bool takeOdd (
int i) {
return 0 != i % 2; }
140 static bool takeEve (
int i) {
return 0 == i % 2; }
141 static bool takeTrd (
int i) {
return 0 == i % 3; }
144 buildFilterIterator (Iter
const& ii)
152 verifyComparisons (all);
153 verifyComparisons (odd);
155 while (++all && ++odd)
178 typedef vector<uint64_t> Src;
179 typedef Src::iterator SrcIter;
184 for (uint i=0; i < 3*NUM_ELMS; ++i)
187 SeqIter completeSequence (src.begin(), src.end());
188 FilteredSeq filterIter (completeSequence, takeAll);
190 CHECK (!isnil (filterIter));
191 CHECK (0 == *filterIter);
193 CHECK (1 == *filterIter);
195 filterIter.andFilter(takeEve);
196 CHECK (!isnil (filterIter));
197 CHECK (2 == *filterIter);
199 CHECK (4 == *filterIter);
202 filterIter.andFilter(takeTrd);
203 CHECK (!isnil (filterIter));
204 CHECK (6 == *filterIter);
206 CHECK (12 == *filterIter);
208 verifyComparisons (filterIter);
209 pullOut (filterIter);
212 filterIter = {completeSequence, takeTrd};
213 CHECK (!isnil (filterIter));
214 CHECK (0 == *filterIter);
216 CHECK (3 == *filterIter);
218 filterIter.orFilter(takeEve);
219 CHECK (3 == *filterIter);
221 CHECK (4 == *filterIter);
223 CHECK (6 == *filterIter);
224 verifyComparisons (filterIter);
227 filterIter.flipFilter();
228 CHECK (7 == *filterIter);
230 CHECK (11 == *filterIter);
232 CHECK (13 == *filterIter);
234 verifyComparisons (filterIter);
235 pullOut (filterIter);
246 vector<uint> numberz;
247 for (uint i=0; i<NUM_ELMS; ++i)
249 uint n = 1 + rand() % 100;
250 do numberz.push_back(i);
253 CHECK (NUM_ELMS < numberz.size(),
"no repetition in test data??");
255 typedef vector<uint>::iterator SrcIter;
259 SeqIter completeSequence (numberz.begin(), numberz.end());
263 for (; num<NUM_ELMS && !isnil(filtered);
267 CHECK (num == *filtered);
269 CHECK (num == NUM_ELMS && isnil(filtered));
284 CHECK (not isnil(i1));
285 CHECK (not isnil(i2));
286 CHECK (not isnil(i3));
316 static ulong addTwo (
int i) {
return i+2; }
317 static int negate (
int i) {
return -i; }
318 static int idFunc (
int i) {
return i; }
321 buildTransformingIterator (Iter
const& ii)
329 verifyComparisons (idi);
330 verifyComparisons (neg);
338 CHECK (!idi && !neg);
359 CHECK (i1 == i2); CHECK (i2 == i1);
360 CHECK (i1 != iN); CHECK (iN != i1);
361 CHECK (i2 != iN); CHECK (iN != i2);
385 verifyPullLast(Iter
const& ii)
387 Iter::value_type lastElm = pull_last (ii);
388 CHECK (1 == lastElm);
391 CHECK (isnil (emptyIterator));
Iterator tool filtering pulled data according to a predicate.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Additional capabilities for FilterIter, allowing to extend the filter condition underway.
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...
void for_each(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
A collection of frequently used helper functions to support unit testing.
auto singleValIterator(VAL &&something)
Build a SingleValIter: convenience free function shortcut, to pick up just any value and wrap it as L...
Pseudo-Iterator to yield just a single value.
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
auto filterIterator(IT const &src, PRED filterPredicate)
Build a FilterIter: convenience free function shortcut, picking up the involved types automatically...
auto transformIterator(IT const &src, FUN processingFunc)
Build a TransformIter: convenience free function shortcut, picking up the involved types automaticall...
Perform operations "for each element" of a collection.
auto filterRepetitions(IT const &source)
filters away repeated values emitted by source iterator