summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-02-10 15:28:53 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2015-02-10 15:28:53 -0800
commit3bf3249cc7103dcdcbdc3881a546a6cad8e4b65d (patch)
tree5a0d2158dc156b4027ef4f35ab44ef2ea1925d7f
parent687ec913790653f79badc8f5d656c86792e94271 (diff)
downloadtaskflow-3bf3249cc7103dcdcbdc3881a546a6cad8e4b65d.tar.gz
DFS in right order when not starting at the provided node
When the dfs iteration is requested to start at the provided nodes children make sure that we create the stack in the same way as we do its children to ensure that the DFS iteration order is maintained correctly in this situation. Change-Id: I9d5e3a46b4d2349ab1662a634d635b2052be4a55
-rw-r--r--taskflow/tests/unit/test_types.py9
-rw-r--r--taskflow/types/tree.py3
2 files changed, 10 insertions, 2 deletions
diff --git a/taskflow/tests/unit/test_types.py b/taskflow/tests/unit/test_types.py
index 4daea4b..83d938d 100644
--- a/taskflow/tests/unit/test_types.py
+++ b/taskflow/tests/unit/test_types.py
@@ -142,6 +142,15 @@ class TreeTest(test.TestCase):
self.assertEqual(set(['animal', 'reptile', 'mammal', 'horse',
'primate', 'monkey', 'human']), set(things))
+ def test_dfs_itr_order(self):
+ root = self._make_species()
+ things = list([n.item for n in root.dfs_iter(include_self=True)])
+ self.assertEqual(['animal', 'mammal', 'horse', 'primate',
+ 'monkey', 'human', 'reptile'], things)
+ things = list([n.item for n in root.dfs_iter(include_self=False)])
+ self.assertEqual(['mammal', 'horse', 'primate',
+ 'monkey', 'human', 'reptile'], things)
+
class StopWatchTest(test.TestCase):
def setUp(self):
diff --git a/taskflow/types/tree.py b/taskflow/types/tree.py
index 7777044..2386bc9 100644
--- a/taskflow/types/tree.py
+++ b/taskflow/types/tree.py
@@ -40,8 +40,7 @@ class _DFSIter(object):
if self.include_self:
stack.append(self.root)
else:
- for child_node in self.root:
- stack.append(child_node)
+ stack.extend(self.root.reverse_iter())
while stack:
node = stack.pop()
# Visit the node.