found bug and more tests
This commit is contained in:
@@ -19,11 +19,13 @@ module Parfait
|
|||||||
internal_object_length - 1
|
internal_object_length - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# index of item, remeber first item has index 1
|
||||||
|
# return nil if no such item
|
||||||
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(index) == item)
|
if( get(counter) == item)
|
||||||
return counter
|
return counter
|
||||||
end
|
end
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
@@ -31,6 +33,11 @@ module Parfait
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# include? means non nil index
|
||||||
|
def include? item
|
||||||
|
return index_of(item) != nil
|
||||||
|
end
|
||||||
|
|
||||||
# push means add to the end
|
# push means add to the end
|
||||||
# this automatically grows the List
|
# this automatically grows the List
|
||||||
def push value
|
def push value
|
||||||
|
@@ -49,4 +49,14 @@ class TestList < MiniTest::Test
|
|||||||
assert_equal v , @list.get(k)
|
assert_equal v , @list.get(k)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
Reference in New Issue
Block a user