From a7bdc05091f1c80fd09f30df43f63922be7083b7 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 18 Nov 2017 18:26:59 +0100 Subject: [PATCH] WIP: draft first testcase ...just wrapping various kinds of iterators --- src/lib/iter-tree-explorer.hpp | 33 +++++++++++------ tests/library/iter-tree-explorer-test.cpp | 44 ++++++++++++++++++----- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/lib/iter-tree-explorer.hpp b/src/lib/iter-tree-explorer.hpp index e01603342..f52f8ae07 100644 --- a/src/lib/iter-tree-explorer.hpp +++ b/src/lib/iter-tree-explorer.hpp @@ -79,8 +79,9 @@ #include "lib/null-value.hpp" ////////////////TODO #include "lib/util.hpp" -#include ////////////////TODO +//#include //////////////TODO #include ////////////////TODO +#include namespace lib { @@ -102,8 +103,9 @@ namespace lib { */ template - class IterTreeExplorer - : public IterStateWrapper + class TreeExplorer +// : public IterStateWrapper + : 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 (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 + struct _TreeExplorerTraits + { + + }; + + }//(End) TreeExplorer traits /* ==== convenient builder free functions ==== */ -/* template - inline IterExplorer> - exploreIter (IT const& srcSeq) + inline auto + treeExplore (IT&& srcSeq) { - return IterExplorer> (srcSeq); + return TreeExplorer {std::forward(srcSeq)}; } +/* template inline iter_explorer::DepthFirst depthFirst (IT const& srcSeq) diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index 465b24f17..dd31982ee 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -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 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 */