Hi --

Just for fun, I've converted your tests to Test::Unit format.  This is
a drop-in replacement for everything after the module Enumerable
extensions.

A few comments:

1. I'm still not sold on the whole thing :-)  But it's extremely
interesting.

2. I had to change #next to #i_next, because it was next'ing integers and
characters.

3. #odd? and #even? are, in my view, too "meta".  When I see "x.odd?",
it's virtually impossible not to expect that it's testing an integer
for oddness.

4. Are you sure you want #next (or #i_next, or whatever) to consume
items?  What if you want to grab the next item, but also want to
iterate to that item in the normal way?  You seem to have less
functionality here (if I'm right about that) than you would with one
of the "index" methods.

5. I've done some fancy #to_s'ing... not sure if I should have to do
that.  Anyway, I've done it, just to get the tests to pass initially.


David

# -----------------------------------------------------------
if __FILE__ == $0

require "test/unit"   # I know, I know -- I should indent.

class TestMe < Test::Unit::TestCase
  def set_up
    @a = %w[zero one two three four]
  end
  def test1
    i = 0
    @a.iterate do |x|
      assert(x.first?) if x == "zero"
      assert(x.even?) if i % 2 == 0
      assert(x.odd?)  if i % 2 == 1
      assert(x.last?) if x == "four"
      i += 1
    end
  end

puts

# Same array a -- capitalize every other entry

  def test2
    @a.iterate do |x|
      if x.odd?
	x.value = x.value.upcase
      end
    end
    assert_equal(@a, %w{ zero ONE two THREE four })
  end


# Problem: For a list of items, grab the "parent"
# and the fixed number of children following. A
# parent is a single letter -- if it's a vowel
# [aeiou] it has a single child; a consonant will
# have three children

  def test3
    puts
    items = %w[ b 0 1 2 a 3 c 3 4 5 d 6 7 8 e 9 ]
    i = 0
    items.iterate do |item|
      parent = item.value
      if parent =~ /[aeiou]/
	assert_equal(item.i_next.to_s, items[i+=1])
      else
	arr = []
	3.times { |n| arr << item.i_next.to_s }
	arr.each_index {|n| assert_equal(arr[n],items[i+n+1])}
	i += 3
      end
      i += 1
    end
  end
end
end