From 767156e912639761ea7de8eb1893667e450c0516 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 16 Sep 2018 01:04:00 +0200 Subject: [PATCH] TreeExplorer: unit test coverage for injected custom layer --- tests/library/iter-tree-explorer-test.cpp | 45 +++++++++++++++++++++++ wiki/thinkPad.ichthyo.mm | 26 ++++++++----- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index 84f53459b..cb8fc8470 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -275,6 +275,7 @@ namespace test{ verify_expand_rootCurrent(); verify_transformOperation(); verify_combinedExpandTransform(); + verify_customProcessingLayer(); verify_scheduledExpansion(); verify_FilterIterator(); verify_FilterChanges(); @@ -720,6 +721,50 @@ namespace test{ } + /** + * demo of a custom processing layer + * interacting directly with the iteration mechanism. + * @note we can assume `SRC` is itself a Lumiera Iterator + */ + template + struct MagicTestRubbish + : public SRC + { + using SRC::SRC; + + void + iterNext() + { + ++(*this); + if (*this) + ++(*this); + } + }; + + /** @test extension point to inject a client-defined custom processing layer + * This special builder function allows to install a template, which needs to wrap + * a source iterator and expose a _state core like_ interface. We demonstrate this + * extension mechanism here by defining a processing layer which skips each other element. + */ + void + verify_customProcessingLayer() + { + CHECK (materialise( + treeExplore(CountDown{7}) + .processingLayer() + ) + == "7-5-3-1"); + + CHECK (materialise( + treeExplore(CountDown{7}) + .transform([](uint v){ return 2*v; }) + .processingLayer() + .filter([](int v){ return v % 3; }) + ) + == "14-10-2"); + } + + /** @test child expansion can be scheduled to happen on next iteration. * As such, _"child expansion"_ happens right away, thereby consuming a node diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 4f61fb890..f1510183b 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -31144,10 +31144,10 @@ - + - - + + @@ -31162,16 +31162,22 @@ - + - - + + - - + + + + + + + + + + - -