WIP: draft first testcase

...just wrapping various kinds of iterators
This commit is contained in:
Fischlurch 2017-11-18 18:26:59 +01:00
parent c3b04af76f
commit a7bdc05091
2 changed files with 58 additions and 19 deletions

View file

@ -79,8 +79,9 @@
#include "lib/null-value.hpp" ////////////////TODO
#include "lib/util.hpp"
#include <boost/utility/enable_if.hpp> ////////////////TODO
//#include <boost/utility/enable_if.hpp> //////////////TODO
#include <stack> ////////////////TODO
#include <utility>
namespace lib {
@ -102,8 +103,9 @@ namespace lib {
*/
template<class SRC
>
class IterTreeExplorer
: public IterStateWrapper<typename SRC::value_type, SRC>
class TreeExplorer
// : public IterStateWrapper<typename SRC::value_type, SRC>
: public SRC
{
@ -114,7 +116,7 @@ namespace lib {
/** by default create an empty iterator */
IterTreeExplorer() { }
TreeExplorer() { }
/** wrap an iterator-like state representation
@ -123,8 +125,8 @@ namespace lib {
* by the core, and it provides the (monad) bind operator.
*/
explicit
IterTreeExplorer (SRC const& iterStateCore)
: IterStateWrapper<value_type, SRC> (iterStateCore)
TreeExplorer (SRC iterStateCore)
: SRC{std::move (iterStateCore)}
{ }
@ -150,22 +152,33 @@ namespace lib {
using std::function;
using meta::_Fun;
}//(End) namespace iter_explorer : predefined policies and configurations
namespace {
template<class SRC, typename SEL=void>
struct _TreeExplorerTraits
{
};
}//(End) TreeExplorer traits
/* ==== convenient builder free functions ==== */
/*
template<class IT>
inline IterExplorer<iter_explorer::WrappedSequence<IT>>
exploreIter (IT const& srcSeq)
inline auto
treeExplore (IT&& srcSeq)
{
return IterExplorer<iter_explorer::WrappedSequence<IT>> (srcSeq);
return TreeExplorer<SrcIter> {std::forward<IT>(srcSeq)};
}
/*
template<class IT>
inline iter_explorer::DepthFirst<IT>
depthFirst (IT const& srcSeq)

View file

@ -76,6 +76,7 @@ namespace test{
using util::isSameObject;
using lib::iter_stl::eachElm;
using lumiera::error::LUMIERA_ERROR_ITER_EXHAUST;
using std::vector;
using std::string;
@ -228,6 +229,7 @@ namespace test{
virtual void
run (Arg)
{
verify_wrappedState();
verify_wrappedIterator();
verify_mapOperation();
@ -244,13 +246,13 @@ namespace test{
* TreeExplorer just wraps an iterable state.
*/
void
verify_wrappedIterator()
verify_wrappedState()
{
NumberSequence ii = seq(9);
auto ii = treeExplore (State{1,5});
CHECK (!isnil (ii));
CHECK (0 == *ii);
++ii;
CHECK (1 == *ii);
++ii;
CHECK (2 == *ii);
pullOut(ii);
CHECK ( isnil (ii));
CHECK (!ii);
@ -258,17 +260,41 @@ namespace test{
VERIFY_ERROR (ITER_EXHAUST, *ii );
VERIFY_ERROR (ITER_EXHAUST, ++ii );
ii = seq(5);
CHECK (materialise(ii) == "0-1-2-3-4");
ii = seq(5,8);
ii = treeExplore (State{0,5});
CHECK (materialise(ii) == "0-1-2-3-4-5");
ii = treeExplore (State{5,7});
CHECK (materialise(ii) == "5-6-7");
ii = NIL_Sequence;
ii = treeExplore (State{1,0});
CHECK ( isnil (ii));
CHECK (!ii);
}
/** @test TreeExplorer is able to wrap any _Lumiera Forward Iterator_ */
void
verify_wrappedIterator()
{
vector<int> numz{1,-2,3,-5,8,-13};
auto ii = eachElm(numz);
CHECK (!isnil (ii));
CHECK (1 == *ii);
++ii;
CHECK (-2 == *ii);
auto jj = treeExplore(ii);
CHECK (!isnil (jj));
CHECK (-2 == *jj);
++jj;
CHECK (3 == *jj);
// we passed a LValue-Ref, thus a copy was made
CHECK (-2 == *ii);
CHECK (materialise(ii) == "-2-3--5-8--13");
CHECK (materialise(jj) == "-3--5-8--13");
}
/** @test pipe each result through a transformation function
*/