28 #include <boost/lexical_cast.hpp> 37 using boost::lexical_cast;
42 using LERR_(ITER_EXHAUST);
55 data_.push_back(num--);
58 typedef vector<int>::iterator sourceIter;
61 iterator begin() {
return iterator(data_.begin(),data_.end()); }
62 iterator end() {
return iterator(); }
84 typedef TestSource::iterator Iter;
92 NUM_ELMS = firstVal (arg, 10);
94 TestSource source(NUM_ELMS);
96 pullOut (source.begin());
97 verifyComparisons (source.begin());
100 buildFilterIterator (source.begin());
101 Iter ii (source.begin());
103 buildFilterIterator (ii);
104 verify_filterExtension();
105 verify_filterRepetitions();
107 buildWrappedSingleElement();
109 buildTransformingIterator (source.begin());
111 verifyPullLast(source.begin());
118 pullOut (IT
const& ii)
121 cout <<
"::" << *
iter;
127 static bool takeAll (
int) {
return true; }
128 static bool takeOdd (
int i) {
return 0 != i % 2; }
129 static bool takeEve (
int i) {
return 0 == i % 2; }
130 static bool takeTrd (
int i) {
return 0 == i % 3; }
133 buildFilterIterator (Iter
const& ii)
141 verifyComparisons (all);
142 verifyComparisons (odd);
144 while (++all && ++odd)
167 typedef vector<uint64_t> Src;
168 typedef Src::iterator SrcIter;
173 for (uint i=0; i < 3*NUM_ELMS; ++i)
176 SeqIter completeSequence (src.begin(), src.end());
177 FilteredSeq filterIter (completeSequence, takeAll);
179 CHECK (!isnil (filterIter));
180 CHECK (0 == *filterIter);
182 CHECK (1 == *filterIter);
184 filterIter.andFilter(takeEve);
185 CHECK (!isnil (filterIter));
186 CHECK (2 == *filterIter);
188 CHECK (4 == *filterIter);
191 filterIter.andFilter(takeTrd);
192 CHECK (!isnil (filterIter));
193 CHECK (6 == *filterIter);
195 CHECK (12 == *filterIter);
197 verifyComparisons (filterIter);
198 pullOut (filterIter);
201 filterIter = {completeSequence, takeTrd};
202 CHECK (!isnil (filterIter));
203 CHECK (0 == *filterIter);
205 CHECK (3 == *filterIter);
207 filterIter.orFilter(takeEve);
208 CHECK (3 == *filterIter);
210 CHECK (4 == *filterIter);
212 CHECK (6 == *filterIter);
213 verifyComparisons (filterIter);
216 filterIter.flipFilter();
217 CHECK (7 == *filterIter);
219 CHECK (11 == *filterIter);
221 CHECK (13 == *filterIter);
223 verifyComparisons (filterIter);
224 pullOut (filterIter);
235 vector<uint> numberz;
236 for (uint i=0; i<NUM_ELMS; ++i)
238 uint n = 1 +
rani (100);
239 do numberz.push_back(i);
242 CHECK (NUM_ELMS < numberz.size(),
"no repetition in test data??");
244 typedef vector<uint>::iterator SrcIter;
248 SeqIter completeSequence (numberz.begin(), numberz.end());
252 for (; num<NUM_ELMS && !isnil(filtered);
256 CHECK (num == *filtered);
258 CHECK (num == NUM_ELMS && isnil(filtered));
273 CHECK (not isnil(i1));
274 CHECK (not isnil(i2));
275 CHECK (not isnil(i3));
305 static ulong addTwo (
int i) {
return i+2; }
306 static int negate (
int i) {
return -i; }
307 static int idFunc (
int i) {
return i; }
310 buildTransformingIterator (Iter
const& ii)
318 verifyComparisons (idi);
319 verifyComparisons (neg);
327 CHECK (!idi && !neg);
348 CHECK (i1 == i2); CHECK (i2 == i1);
349 CHECK (i1 != iN); CHECK (iN != i1);
350 CHECK (i2 != iN); CHECK (iN != i2);
374 verifyPullLast(Iter
const& ii)
376 Iter::value_type lastElm = pull_last (ii);
377 CHECK (1 == lastElm);
380 CHECK (isnil (emptyIterator));
Iterator tool filtering pulled data according to a predicate.
int rani(uint bound=_iBOUND())
#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.
Simplistic 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