fix classic index bug

This commit is contained in:
Torsten Ruger 2015-05-24 15:05:58 +03:00
parent 6786855e95
commit 1170761922
2 changed files with 2 additions and 1 deletions

View File

@ -24,7 +24,7 @@ module Parfait
def index_of( item ) def index_of( item )
max = self.get_length max = self.get_length
counter = 1 counter = 1
while( counter < max ) while( counter <= max )
if( get(counter) == item) if( get(counter) == item)
return counter return counter
end end

View File

@ -52,6 +52,7 @@ class TestList < MiniTest::Test
def test_index_of def test_index_of
test_many_get test_many_get
assert_equal 2 , @list.index_of( :two ) assert_equal 2 , @list.index_of( :two )
assert_equal 3 , @list.index_of( :three )
assert_equal nil , @list.index_of( :four ) assert_equal nil , @list.index_of( :four )
end end
def test_incude def test_incude