add find method to indexed

This commit is contained in:
Torsten Ruger 2016-12-15 14:00:03 +02:00
parent b93f207638
commit 2b3f9c398e
2 changed files with 19 additions and 0 deletions

View File

@ -133,6 +133,16 @@ module Parfait
self
end
def find
index = 1
while index <= self.get_length
item = get(index)
return item if yield item
index = index + 1
end
return nil
end
def set_length len
was = self.get_length
return if was == len

View File

@ -137,6 +137,15 @@ class TestList < MiniTest::Test
end
assert_equal 2 , counter
end
def test_find
@list.set(1,1)
@list.set(2,2)
assert_equal 2, @list.find{|i| i == 2}
end
def test_not_find
@list.set(1,1)
assert_nil @list.find{|i| i == 3}
end
def test_delete_at
test_many_get
assert @list.delete_at 2