Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement List#index (aliased as #find_index).
- Loading branch information
Simon Harris
committed
Jan 26, 2010
1 parent
2d8569d
commit dd1099d
Showing
3 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') | ||
|
||
require 'hamster/list' | ||
|
||
describe Hamster::List do | ||
|
||
[:index, :find_index].each do |method| | ||
|
||
describe "##{method}" do | ||
|
||
describe "on a really big list" do | ||
|
||
before do | ||
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH) | ||
end | ||
|
||
it "doesn't run out of stack" do | ||
lambda { @list.send(method, nil) }.should_not raise_error | ||
end | ||
|
||
end | ||
|
||
[ | ||
[[], "A", nil], | ||
[[], nil, nil], | ||
[["A"], "A", 0], | ||
[["A"], "B", nil], | ||
[["A"], nil, nil], | ||
[["A", "B", nil], "A", 0], | ||
[["A", "B", nil], "B", 1], | ||
[["A", "B", nil], nil, 2], | ||
[["A", "B", nil], "C", nil], | ||
[[2], 2, 0], | ||
[[2], 2.0, 0], | ||
[[2.0], 2.0, 0], | ||
[[2.0], 2, 0], | ||
].each do |values, item, expected| | ||
|
||
describe "looking for #{item.inspect} in #{values.inspect}" do | ||
|
||
before do | ||
list = Hamster.list(*values) | ||
@result = list.send(method, item) | ||
end | ||
|
||
it "returns #{expected.inspect}" do | ||
@result.should == expected | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters