add find method to indexed
This commit is contained in:
parent
b93f207638
commit
2b3f9c398e
@ -133,6 +133,16 @@ module Parfait
|
|||||||
self
|
self
|
||||||
end
|
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
|
def set_length len
|
||||||
was = self.get_length
|
was = self.get_length
|
||||||
return if was == len
|
return if was == len
|
||||||
|
@ -137,6 +137,15 @@ class TestList < MiniTest::Test
|
|||||||
end
|
end
|
||||||
assert_equal 2 , counter
|
assert_equal 2 , counter
|
||||||
end
|
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
|
def test_delete_at
|
||||||
test_many_get
|
test_many_get
|
||||||
assert @list.delete_at 2
|
assert @list.delete_at 2
|
||||||
|
Loading…
Reference in New Issue
Block a user