--bcaec54306faa23c5904a24f074a
Content-Type: text/plain; charset=ISO-8859-1

Hello,

I'm looking to improve my skills as a Rubyist and would like to know if the
"depth" method could be expressed more precisely.  Any help would be greatly
appreciated, thanks!

require 'test/unit'

class Node
  attr_accessor :value, :lchild, :rchild

  def depth
    [lchild ? lchild.depth : 0, rchild ? rchild.depth : 0].max + 1
  end
end

class NodeTest < Test::Unit::TestCase
  def setup
    @n  ode.new
  end

  def test_depth_of_one
    @n.lchild  ode.new
    @n.lchild.lchild  ode.new
    @n.rchild  ode.new
    assert @n.depth 1, "depth of node should be one, was #{@n.depth}"
  end

  def test_depth_of_two
    @n.lchild  ode.new
    @n.rchild  ode.new
    assert @n.lchild.depth 1, "depth of lchild should be one"
    assert @n.rchild.depth 1, "depth of rchild should be one"
    assert @n.depth 2, "depth of tree should be two, was #{@n.depth}"
  end
end

-- 

Mark
mark / deployfx.com
 <mark / deployfx.com>

--bcaec54306faa23c5904a24f074a--