# Ruby Treasures 0.1
# Copyright (C) 2001 Paul Brannan <paul@atdesk.com>
# 
# You may distribute this software under the same terms as Ruby (see the file
# COPYING that was distributed with this library).
# 
module IndexableTest
  def test_index
    DS_Test_Case.method_checked(:index, @test_container)
    [0, 1, 2, 5, N-1, N].each do |i|
      a = generate_random_container(i, @analgous_container)
      l = generate_container_from_analgous(a)
      a.each_pair do |key, value|
        a_index = a.index(value)
        l_index = l.index(value)
        assert_equal a_index, l_index
      end
    end
  end

  def test_indices
    DS_Test_Case.method_checked(:indices, @test_container)
    DS_Test_Case.method_checked(:indexes, @test_container)
    for i in 0...N do
      a = generate_random_container(i, @analgous_container)
      l = generate_container_from_analgous(a)
      assert_containers_equal(a.indexes, l.indexes)
    end
  end

  def test_each_pair_and_index
    DS_Test_Case.method_checked(:each_pair, @test_container)
    DS_Test_Case.method_checked(:each_index, @test_container)
    [0, 1, 2, 5, N-1, N].each do |i|
      a = generate_random_container(i, @analgous_container)
      l = generate_container_from_analgous(a)
      assert_containers_equal(a, l, :each_pair)
      assert_containers_equal(a, l, :each_index)
    end
  end

  def test_bracket_operators
    DS_Test_Case.method_checked(:[], @test_container)
    DS_Test_Case.method_checked(:[]=, @test_container)
    # TODO: these are tested sufficiently elsewhere, but they should be tested
    # here anyway, just in case.
  end
end
