Skip to content

Commit

Permalink
Merge pull request #43 from aidansteele/master
Browse files Browse the repository at this point in the history
Reverted buggy node_depth optimisation
  • Loading branch information
evolve75 committed Jan 25, 2015
2 parents 4c22416 + 7f5b81e commit 9ae506d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tree/utils/metrics_methods.rb
Expand Up @@ -94,7 +94,8 @@ def node_height
#
# @return [Integer] Depth of this node.
def node_depth
@node_depth ||= is_root? ? 0 : (1 + parent.node_depth)
return 0 if is_root?
1 + parent.node_depth
end

# @!attribute [r] level
Expand Down
3 changes: 3 additions & 0 deletions test/test_tree.rb
Expand Up @@ -1018,6 +1018,9 @@ def test_node_depth
end

assert_equal(2, @child4.node_depth, "Child 4 should have depth 2")

@root << @child5 << @child3
assert_equal(3, @child4.node_depth, "Child 4 should have depth 3 after Child 5 inserted above")
end

# Test the level method. Since this is an alias of node_depth, we just test for equivalence
Expand Down

0 comments on commit 9ae506d

Please sign in to comment.