On Dec 14, 2007, at 10:14 AM, Paul Irofti wrote:

> On 2007-12-14, Rick DeNatale <rick.denatale / gmail.com> wrote:
>> On 12/14/07, Ruby Quiz <james / grayproductions.net> wrote:
>>
>>>        The Game
>>>
>>> Eric Hodel described Programmer Ping-Pong in his RubyConf 2007  
>>> presentation.  I
>>> wasn't familiar with the concept before that and it sounds like  
>>> fun, so let's
>>> all try it out together.
>>>
>>> The rules are:
>>>
>>>        * This quiz does not have a no-spoiler period so you may
>>>          submit at anytime after reading this message
>>>        * I'll make the initial serve, starting the quiz off with
>>>          a single failing test
>>>        * Anyone can return the ball at anytime by doing exactly
>>>          two things, in order:  make all tests pass including the
>>>          recently added failure and then add a new failing test
>>>          of your own
>>
>> We're doing this in the true tdd spirit of making very small steps  
>> right.
>>
>> Okay, first return.
>
> Hmm, when I posted no one answered, but I guess you got there first.
> Does your version count as the next? Or how is this settled? We seem  
> to
> have written similar things anyways.
>
> -- 
> everything is simple, we're stupid
> contact at gmail

I'll settle that.  Since your tests were equivalent, I went with  
Rick's since I saw it first:

avl_tree.rb

#!/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
   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

end
__END__

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com