-
Notifications
You must be signed in to change notification settings - Fork 609
/
new_spec.rb
43 lines (34 loc) · 978 Bytes
/
new_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require File.expand_path('../../../../spec_helper', __FILE__)
describe "Array::Iterator.new" do
before :each do
ScratchPad.record []
end
it "creates a forward iterator" do
iter = Array::Iterator.new [1, 2, 3], 1, false
while iter.next
ScratchPad << iter.item
end
ScratchPad.recorded.should == [1, 2, 3]
end
it "creates a forward iterator with a step size > 1" do
iter = Array::Iterator.new [1, 2, 3], 2, false
while iter.next
ScratchPad << iter.item
end
ScratchPad.recorded.should == [1, 3]
end
it "creates a reverse iterator" do
iter = Array::Iterator.new [1, 2, 3], 1, true
while iter.rnext
ScratchPad << iter.item
end
ScratchPad.recorded.should == [3, 2, 1]
end
it "creates a reverse iterator with a step size > 1" do
iter = Array::Iterator.new [1, 2, 3], 2, true
while iter.rnext
ScratchPad << iter.item
end
ScratchPad.recorded.should == [3, 1]
end
end