Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerators for TreeNode#postordered_each and TreeNode#breadth_each faulty #31

Closed
MMF2 opened this issue Oct 19, 2014 · 2 comments
Closed
Assignees
Labels
Milestone

Comments

@MMF2
Copy link

MMF2 commented Oct 19, 2014

If TreeNode#postordered_each or TreeNode#breadth_each are called without a block to get the enumerators, these enumerators incorrectly enumerate in the same order as TreeNode#preordered_each. If called instead with blocks they enumerate correctly.
Example:
t = Tree::TreeNode.new('1')
t << Tree::TreeNode.new('2') << Tree::TreeNode.new('4')
t << Tree::TreeNode.new('3') << Tree::TreeNode.new('5')
t['3'] << Tree::TreeNode.new('6')
a = []
t.postordered_each {|n| a << n.name}
a # => ["4", "2", "5", "6", "3", "1"](correct postorder)
t.postordered_each.collect {|n| n.name} # => ["1", "2", "4", "3", "5", "6"](that's preorder instead of
postorder)

@evolve75 evolve75 added the Bug label Oct 25, 2014
@evolve75 evolve75 added this to the 0.9.5 milestone Oct 25, 2014
@evolve75 evolve75 self-assigned this Oct 25, 2014
@evolve75
Copy link
Owner

This bug is due to the code-line:

     return self.to_enum unless block_given? 

in both postordered_each and breadth_each methods.

@evolve75
Copy link
Owner

Fixed. Will be in 0.9.5pre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants