found bug and more tests
This commit is contained in:
parent
531d3e181a
commit
b4eb14e639
@ -19,11 +19,13 @@ module Parfait
|
||||
internal_object_length - 1
|
||||
end
|
||||
|
||||
# index of item, remeber first item has index 1
|
||||
# return nil if no such item
|
||||
def index_of( item )
|
||||
max = self.get_length
|
||||
counter = 1
|
||||
while( counter < max )
|
||||
if( get(index) == item)
|
||||
if( get(counter) == item)
|
||||
return counter
|
||||
end
|
||||
counter = counter + 1
|
||||
@ -31,6 +33,11 @@ module Parfait
|
||||
return nil
|
||||
end
|
||||
|
||||
# include? means non nil index
|
||||
def include? item
|
||||
return index_of(item) != nil
|
||||
end
|
||||
|
||||
# push means add to the end
|
||||
# this automatically grows the List
|
||||
def push value
|
||||
|
@ -49,4 +49,14 @@ class TestList < MiniTest::Test
|
||||
assert_equal v , @list.get(k)
|
||||
end
|
||||
end
|
||||
def test_index_of
|
||||
test_many_get
|
||||
assert_equal 2 , @list.index_of( :two )
|
||||
assert_equal nil , @list.index_of( :four )
|
||||
end
|
||||
def test_incude
|
||||
test_many_get
|
||||
assert_equal true , @list.include?( :two )
|
||||
assert_equal false , @list.include?( :four )
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user