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 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
require File.dirname(__FILE__) + "/../spec_helper"
import "java.util.ArrayList"
describe "List Ruby extensions" do
before(:each) do
@data = ["foo", "quux", "bar", "aa"]
@list = ArrayList.new(@data)
end
it "should be sortable with sort() without block" do
@list.sort.to_a.should == @data.sort
end
it "should be sortable with sort() with block" do
result = @list.sort do |a, b|
a.length <=> b.length
end
expected = @data.sort do |a, b|
a.length <=> b.length
end
result.to_a.should == expected
end
it "should be sortable with sort!() without block" do
list = ArrayList.new(@data)
list.sort!
list.to_a.should == @data.sort
end
it "should be sortable with sort!() with block" do
list = ArrayList.new(@data)
list.sort! do |a, b|
a.length <=> b.length
end
expected = @data.sort do |a, b|
a.length <=> b.length
end
list.to_a.should == expected
end
it "should support slicing with 2 arguments" do
@list[0,3].to_a.should == @data[0,3]
end
it "should support slicing with inclusive ranges" do
@list[0..3].to_a.should == @data[0..3]
end
it "should support slicing with exclusive ranges" do
@list[0...2].to_a.should == @data[0...2]
end
end
|