Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: beb71c99dd7c
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 64ef832d5259
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jun 26, 2015

  1. Copy the full SHA
    1bdbc58 View commit details
  2. Copy the full SHA
    64ef832 View commit details
110 changes: 110 additions & 0 deletions spec/truffle/specs/truffle/array/max_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Copyright (c) 2008 Engine Yard, Inc. All rights reserved.

# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:

# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

require_relative '../../../../ruby/spec_helper'

# From Enumerable#max, adapted to Array since we have Array#max.
describe "Array#max" do
before :each do
@a = [2, 4, 6, 8, 10]

@e_strs = ["333", "22", "666666", "1", "55555", "1010101010"]
@e_ints = [333, 22, 666666, 55555, 1010101010]
end

it "max should return the maximum element" do
[18, 42].max.should == 42
[2, 5, 3, 6, 1, 4].max.should == 6
end

it "returns the maximum element (basics cases)" do
[55].max.should == 55

[11,99].max.should == 99
[99,11].max.should == 99
[2, 33, 4, 11].max.should == 33

[1,2,3,4,5].max.should == 5
[5,4,3,2,1].max.should == 5
[1,4,3,5,2].max.should == 5
[5,5,5,5,5].max.should == 5

["aa","tt"].max.should == "tt"
["tt","aa"].max.should == "tt"
["2","33","4","11"].max.should == "4"

@e_strs.max.should == "666666"
@e_ints.max.should == 1010101010
end

it "returns nil for an empty Enumerable" do
[].max.should == nil
end

it "raises a NoMethodError for elements without #<=>" do
lambda do
[BasicObject.new, BasicObject.new].max
end.should raise_error(NoMethodError)
end

it "raises an ArgumentError for incomparable elements" do
lambda do
[11,"22"].max
end.should raise_error(ArgumentError)
lambda do
[11,12,22,33].max{|a, b| nil}
end.should raise_error(ArgumentError)
end

it "returns the maximum element (with block)" do
# with a block
["2","33","4","11"].max {|a,b| a <=> b }.should == "4"
[ 2 , 33 , 4 , 11 ].max {|a,b| a <=> b }.should == 33

["2","33","4","11"].max {|a,b| b <=> a }.should == "11"
[ 2 , 33 , 4 , 11 ].max {|a,b| b <=> a }.should == 2

@e_strs.max {|a,b| a.length <=> b.length }.should == "1010101010"

@e_strs.max {|a,b| a <=> b }.should == "666666"
@e_strs.max {|a,b| a.to_i <=> b.to_i }.should == "1010101010"

@e_ints.max {|a,b| a <=> b }.should == 1010101010
@e_ints.max {|a,b| a.to_s <=> b.to_s }.should == 666666
end

it "returns the minimum for enumerables that contain nils" do
arr = [nil, nil, true]
arr.max { |a, b|
x = a.nil? ? 1 : a ? 0 : -1
y = b.nil? ? 1 : b ? 0 : -1
x <=> y
}.should == nil
end

it "gathers whole arrays as elements when each yields multiple" do
multi = [[1,2], [3,4,5], [6,7,8,9]]
multi.max.should == [6, 7, 8, 9]
end

end
115 changes: 115 additions & 0 deletions spec/truffle/specs/truffle/array/min_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Copyright (c) 2008 Engine Yard, Inc. All rights reserved.

# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:

# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

require_relative '../../../../ruby/spec_helper'

# From Enumerable#min, adapted to Array since we have Array#min.
describe "Array#min" do
before :each do
@a = [2, 4, 6, 8, 10]

@e_strs = ["333", "22", "666666", "1", "55555", "1010101010"]
@e_ints = [ 333, 22, 666666, 55555, 1010101010]
end

it "min should return the minimum element" do
[18, 42].min.should == 18
[2, 5, 3, 6, 1, 4].min.should == 1
end

it "returns the minimum (basic cases)" do
[55].min.should == 55

[11,99].min.should == 11
[99,11].min.should == 11
[2, 33, 4, 11].min.should == 2

[1,2,3,4,5].min.should == 1
[5,4,3,2,1].min.should == 1
[4,1,3,5,2].min.should == 1
[5,5,5,5,5].min.should == 5

["aa","tt"].min.should == "aa"
["tt","aa"].min.should == "aa"
["2","33","4","11"].min.should == "11"

@e_strs.min.should == "1"
@e_ints.min.should == 22
end

it "returns nil for an empty Enumerable" do
[].min.should be_nil
end

it "raises a NoMethodError for elements without #<=>" do
lambda do
[BasicObject.new, BasicObject.new].min
end.should raise_error(NoMethodError)
end

it "raises an ArgumentError for incomparable elements" do
lambda do
[11,"22"].min
end.should raise_error(ArgumentError)
lambda do
[11,12,22,33].min{|a, b| nil}
end.should raise_error(ArgumentError)
end

it "returns the minimum when using a block rule" do
["2","33","4","11"].min {|a,b| a <=> b }.should == "11"
[ 2 , 33 , 4 , 11 ].min {|a,b| a <=> b }.should == 2

["2","33","4","11"].min {|a,b| b <=> a }.should == "4"
[ 2 , 33 , 4 , 11 ].min {|a,b| b <=> a }.should == 33

[ 1, 2, 3, 4 ].min {|a,b| 15 }.should == 1

[11,12,22,33].min{|a, b| 2 }.should == 11
@i = -2
[11,12,22,33].min{|a, b| @i += 1 }.should == 12

@e_strs.min {|a,b| a.length <=> b.length }.should == "1"

@e_strs.min {|a,b| a <=> b }.should == "1"
@e_strs.min {|a,b| a.to_i <=> b.to_i }.should == "1"

@e_ints.min {|a,b| a <=> b }.should == 22
@e_ints.min {|a,b| a.to_s <=> b.to_s }.should == 1010101010
end

it "returns the minimum for enumerables that contain nils" do
arr = [nil, nil, true]
arr.min { |a, b|
x = a.nil? ? -1 : a ? 0 : 1
y = b.nil? ? -1 : b ? 0 : 1
x <=> y
}.should == nil
end

it "gathers whole arrays as elements when each yields multiple" do
multi = [[1,2], [3,4,5], [6,7,8,9]]
multi.min.should == [1, 2]
end

end
3 changes: 3 additions & 0 deletions spec/truffle/tags/truffle/array/max_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:Array#max raises an ArgumentError for incomparable elements
fails:Array#max returns the maximum element (with block)
fails:Array#max returns the minimum for enumerables that contain nils
3 changes: 3 additions & 0 deletions spec/truffle/tags/truffle/array/min_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:Array#min raises an ArgumentError for incomparable elements
fails:Array#min returns the minimum when using a block rule
fails:Array#min returns the minimum for enumerables that contain nils