Skip to content

Commit

Permalink
Merge pull request #9 from bkutil/check_height
Browse files Browse the repository at this point in the history
Fix raise on check_height for empty RB tree
  • Loading branch information
nahi committed Nov 11, 2014
2 parents f2caedb + 380db3b commit bf60515
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/red_black_tree.rb
Expand Up @@ -142,8 +142,8 @@ def dump_sexp

# for debugging
def check_height
lh = @left.empty? ? 0 : @left.check_height
rh = @right.empty? ? 0 : @right.check_height
lh = @left.nil? || @left.empty? ? 0 : @left.check_height
rh = @right.nil? || @right.empty? ? 0 : @right.check_height
if red?
if @left.red? or @right.red?
puts dump_tree(STDERR)
Expand Down
6 changes: 6 additions & 0 deletions test/test_red_black_tree.rb
Expand Up @@ -608,6 +608,12 @@ def test_values_for_empty_tree
assert_equal [], h.values
end

def test_check_height_on_empty_tree
h = create_test_target

assert_nothing_raised { h.root.check_height }
end

if RUBY_VERSION >= '1.9.0'
# In contrast to RadixTree, RedBlackTree just uses String#<=> as-is
def test_encoding
Expand Down

0 comments on commit bf60515

Please sign in to comment.