TreeExplorer: fix bug in Filter layer

Fillter needs to be re-evaluated, when an downstream entity requests
expandChildren() onto an upstream source. And obviously the ordering
of the chained calls was wrong here.

As it turns out, I had discovered that necessity to re-evaluate with
the Transformer layer. There is a dedicated test case for that, but
I cut short on verifying the filter in that situation as well, so
that piece of broken copy-n-paste code went through undetected.

This is in fact a rather esoteric corner case, because it is only
triggered when the expandChildren() call is passed through the filter.
When otoh the filter sits /after/ the entity generating the expandChildren()
calls, everything works as intended. And the latter is the typical standard
usage situation of an recursive evalutation algorithm: the filter is here
used as final part to drive the evaluation ahead and pick the solutions.
This commit is contained in:
Fischlurch 2018-09-02 16:27:56 +02:00
parent 3fc5a94b87
commit 757258fb3a
3 changed files with 13 additions and 11 deletions

View file

@ -885,8 +885,8 @@ namespace lib {
void
expandChildren()
{
pullFilter();
SRC::expandChildren();
pullFilter();
}
public: /* === Iteration control API for IterableDecorator === */

View file

@ -785,13 +785,15 @@ namespace test{
// contrived example to verify interplay of filtering and child expansion;
// especially note that the filter is re-evaluated after expansion happened.
cout << "VERIFY->"
<<materialise(
CHECK (materialise (
treeExplore(CountDown{10})
.expand([](uint i){ return CountDown{i%4==0? i-1 : 0}; })
// .filter([](uint i){ return i%2; })
.expandAll()
)<<endl;
.expand([](uint i){ return CountDown{i%4==0? i-1 : 0}; }) // generate subtree at 8 and 4 ==> 10-9-8-7-6-5-4-3-2-1-3-2-1-7-6-5-4-3-2-1-3-2-1
.filter([](uint i){ return i%2 == 0; })
.expandAll() // Note: sends the expandChildren down through the filter
)
== "10-8-6-4-2-2-6-4-2-2");
// another convoluted example to demonstrate
// - a filter predicate with side-effect

View file

@ -30745,8 +30745,8 @@
<icon BUILTIN="messagebox_warning"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1535894221015" ID="ID_977007729" MODIFIED="1535894381051" TEXT="Bug im Filter-Layer?">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1535894221015" FOLDED="true" ID="ID_977007729" MODIFIED="1535898215661" TEXT="Bug im Filter-Layer">
<icon BUILTIN="button_ok"/>
<node CREATED="1535894239308" ID="ID_1809452702" MODIFIED="1535894251655" TEXT="Reihenfolge des Parent-Aufrufes in expandChildren()"/>
<node CREATED="1535894252195" ID="ID_373085595" MODIFIED="1535894291490" TEXT="kommt mir komisch vor; pullFilter() sollte doch danach kommen"/>
<node CREATED="1535894301413" ID="ID_1630859517" MODIFIED="1535894376961" TEXT="sieht nach copy-n-paste aus">
@ -30780,8 +30780,8 @@
</richcontent>
<icon BUILTIN="ksmiletris"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1535894385009" ID="ID_1130325761" MODIFIED="1535894392233" TEXT="Testfall schreiben">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1535894385009" ID="ID_1130325761" MODIFIED="1535898198283" TEXT="Testfall schreiben">
<icon BUILTIN="button_ok"/>
</node>
</node>
</node>