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: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 12092a9ed7d2
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e7cd02e5660d
Choose a head ref
  • 6 commits
  • 2 files changed
  • 2 contributors

Commits on Mar 5, 2015

  1. Use context for readability

    jsyeo committed Mar 5, 2015

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    08079a6 View commit details
  2. Remove unused @A instance variable

    jsyeo committed Mar 5, 2015
    Copy the full SHA
    c60f95b View commit details
  3. Copy the full SHA
    a92ffc1 View commit details
  4. Copy the full SHA
    6207a97 View commit details
  5. Copy the full SHA
    cf87d32 View commit details
  6. Merge pull request #3343 from jsyeo/max-optional-arg-spec

    Add spec for Enumerable#max optional arg
    Yorick Peterse committed Mar 5, 2015
    Copy the full SHA
    e7cd02e View commit details
Showing with 45 additions and 15 deletions.
  1. +42 −15 spec/ruby/core/enumerable/max_spec.rb
  2. +3 −0 spec/tags/ruby/core/enumerable/max_tags.txt
57 changes: 42 additions & 15 deletions spec/ruby/core/enumerable/max_spec.rb
Original file line number Diff line number Diff line change
@@ -3,13 +3,11 @@

describe "Enumerable#max" do
before :each do
@a = EnumerableSpecs::EachDefiner.new( 2, 4, 6, 8, 10 )

@e_strs = EnumerableSpecs::EachDefiner.new("333", "22", "666666", "1", "55555", "1010101010")
@e_ints = EnumerableSpecs::EachDefiner.new( 333, 22, 666666, 55555, 1010101010)
end

it "max should return the maximum element" do
it "returns the maximum element" do
EnumerableSpecs::Numerous.new.max.should == 6
end

@@ -52,24 +50,25 @@
end.should raise_error(ArgumentError)
end

it "returns the maximum element (with block" do
# with a block
EnumerableSpecs::EachDefiner.new("2","33","4","11").max {|a,b| a <=> b }.should == "4"
EnumerableSpecs::EachDefiner.new( 2 , 33 , 4 , 11 ).max {|a,b| a <=> b }.should == 33
context "when passed a block" do
it "returns the maximum element" do
EnumerableSpecs::EachDefiner.new("2","33","4","11").max {|a,b| a <=> b }.should == "4"
EnumerableSpecs::EachDefiner.new( 2 , 33 , 4 , 11 ).max {|a,b| a <=> b }.should == 33

EnumerableSpecs::EachDefiner.new("2","33","4","11").max {|a,b| b <=> a }.should == "11"
EnumerableSpecs::EachDefiner.new( 2 , 33 , 4 , 11 ).max {|a,b| b <=> a }.should == 2
EnumerableSpecs::EachDefiner.new("2","33","4","11").max {|a,b| b <=> a }.should == "11"
EnumerableSpecs::EachDefiner.new( 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.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_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
@e_ints.max {|a,b| a <=> b }.should == 1010101010
@e_ints.max {|a,b| a.to_s <=> b.to_s }.should == 666666
end
end

it "returns the minimum for enumerables that contain nils" do
it "returns the maximum for enumerables that contain nils" do
arr = EnumerableSpecs::Numerous.new(nil, nil, true)
arr.max { |a, b|
x = a.nil? ? 1 : a ? 0 : -1
@@ -83,4 +82,32 @@
multi.max.should == [6, 7, 8, 9]
end

context "when called with an argument n" do
context "without a block" do
it "returns an array containing the maximum n elements" do
result = @e_ints.max(2)
result.should == [1010101010, 666666]
end
end

context "with a block" do
it "returns an array containing the maximum n elements" do
result = @e_ints.max(2) { |a, b| a * 2 <=> b * 2 }
result.should == [1010101010, 666666]
end
end

context "on a enumerable of length x where x < n" do
it "returns an array containing the maximum n elements of length x" do
result = @e_ints.max(500)
result.length.should == 5
end
end

context "that is negative" do
it "raises an Argument error" do
lambda { @e_ints.max(-1) }.should raise_error(ArgumentError)
end
end
end
end
3 changes: 3 additions & 0 deletions spec/tags/ruby/core/enumerable/max_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:Enumerable#max when called with an argument n without a block returns an array containing the maximum n elements
fails:Enumerable#max when called with an argument n with a block returns an array containing the maximum n elements
fails:Enumerable#max when called with an argument n on a enumerable of length x where x < n returns an array containing the maximum n elements of length x