Permalink
Browse files

Allow #value to be called on empty trees

  • Loading branch information...
1 parent 7e664ff commit 9135e3d67110b20ace7b88f80a983bf48a443b6f @eric eric committed Mar 27, 2012
Showing with 20 additions and 0 deletions.
  1. +4 −0 lib/avl_tree.rb
  2. +4 −0 lib/red_black_tree.rb
  3. +6 −0 test/test_avl_tree.rb
  4. +6 −0 test/test_red_black_tree.rb
View
@@ -17,6 +17,10 @@ def value
nil
end
+ def values
+ []
+ end
+
def size
0
end
@@ -394,6 +394,10 @@ def value
nil
end
+ def values
+ []
+ end
+
def size
0
end
@@ -432,6 +432,12 @@ def test_non_string_keys
assert_equal [1.3, 'a' ], h.first
end
+ def test_values_for_empty_tree
+ h = AVLTree.new
+
+ assert_equal [], h.values
+ end
+
if RUBY_VERSION >= '1.9.0'
# In contrast to RadixTree, AVLTree just uses String#<=> as-is
def test_encoding
@@ -582,6 +582,12 @@ def test_non_string_keys
assert_equal [1.3, 'a' ], h.first
end
+ def test_values_for_empty_tree
+ h = RedBlackTree.new
+
+ assert_equal [], h.values
+ end
+
if RUBY_VERSION >= '1.9.0'
# In contrast to RadixTree, RedBlackTree just uses String#<=> as-is
def test_encoding

0 comments on commit 9135e3d

Please sign in to comment.