From 757258fb3ac9507a71156b1385a4761efd64aa42 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 2 Sep 2018 16:27:56 +0200 Subject: [PATCH] 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. --- src/lib/iter-tree-explorer.hpp | 2 +- tests/library/iter-tree-explorer-test.cpp | 14 ++++++++------ wiki/thinkPad.ichthyo.mm | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lib/iter-tree-explorer.hpp b/src/lib/iter-tree-explorer.hpp index 870747646..650db48cc 100644 --- a/src/lib/iter-tree-explorer.hpp +++ b/src/lib/iter-tree-explorer.hpp @@ -885,8 +885,8 @@ namespace lib { void expandChildren() { - pullFilter(); SRC::expandChildren(); + pullFilter(); } public: /* === Iteration control API for IterableDecorator === */ diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index 02c5d4021..39e9e08d3 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -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->" - < 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 diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 172ad8055..c4a24a536 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -30745,8 +30745,8 @@ - - + + @@ -30780,8 +30780,8 @@ - - + +