add each_with_index to indexed

This commit is contained in:
Torsten Ruger 2016-12-08 12:48:39 +02:00
parent ad91c0a4bf
commit 137d3c9231
2 changed files with 16 additions and 0 deletions

View File

@ -112,6 +112,16 @@ module Parfait
self
end
def each_with_index
index = 1
while index <= self.get_length
item = get(index)
yield item , index
index = index + 1
end
self
end
def each_pair
index = 1
while index <= self.get_length

View File

@ -115,6 +115,12 @@ class TestList < MiniTest::Test
end
assert_equal 0 , shouldda_values.length
end
def test_each_index
set_shouldda
@list.each_with_index do |val , index|
assert_equal @list[index] , val
end
end
def test_each_pair_length
shouldda_values = set_shouldda.values
@list.each_pair do |key,val|