From: Ken Bloom Date: 2007-12-15T01:10:49+09:00 Subject: Re: [QUIZ] Programmer Ping-Pong (#150) #!/usr/bin/env ruby -wKU class AVLTree def initialize @contents = [] end def empty? @contents.empty? end def include?(obj) @contents.include?(obj) end def <<(obj) @contents << obj end def height 1 end end __END__ test_avl_tree.rb #!/usr/bin/env ruby -wKU require "test/unit" require "avl_tree" class TestAVLTree < Test::Unit::TestCase def setup @tree = AVLTree.new end def test_tree_membership assert_equal(true, @tree.empty?) assert_equal(false, @tree.include?(3)) @tree << 3 assert_equal(false, @tree.empty?) assert_equal(true, @tree.include?(3)) end def test_tree_should_allow_more_than_one_element @tree << 3 @tree << 4 assert(@tree.include?(4)) assert(@tree.include?(3)) end def test_tree_height_of_one_or_two_nodes_is_one @tree << 5 assert_equal 1, @tree.height @tree << 6 assert_equal 1, @tree.height end def test_tree_height_of_three_nodes_is_two @tree << 5 @tree << 6 @tree << 7 assert_equal 2, @tree.height end end __END__ -- Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/