Sha256: 5e06a3e9d5758482e727c3540e2ffe57256216e7c6cab36b0979a3b9e6373ace

Contents?: true

Size: 1.56 KB

Versions: 52

Compression:

Stored size: 1.56 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "1.8.7" do
  describe "Range#max" do
    it "returns the maximum value in the range when called with no arguments" do
      (1..10).max.should == 10
      ('f'..'l').max.should == 'l'
    end

    ruby_version_is "1.9" do
      it "returns the maximum value in the Float range when called with no arguments" do
        (303.20..908.1111).max.should == 908.1111
      end
    end

    it "returns nil when the endpoint is less than the start point" do
      (100..10).max.should be_nil
      ('z'..'l').max.should be_nil
    end

    ruby_version_is "1.9" do
      it "returns nil when the endpoint is less than the start point in a Float range" do
        (3003.20..908.1111).max.should be_nil
      end
    end
  end

  describe "Range#max given a block" do
    it "passes each pair of values in the range to the block" do
      acc = []
      (1..10).max {|a,b| acc << [a,b]; a }
      acc.flatten!
      (1..10).each do |value|
        acc.include?(value).should be_true
      end
    end

    it "passes each pair of elements to the block in reversed order" do
      acc = []
      (1..5).max {|a,b| acc << [a,b]; a }
      acc.should == [[2,1],[3,2], [4,3], [5, 4]]
    end

    it "calls #> and #< on the return value of the block" do
      obj = mock('obj')
      obj.should_receive(:>).exactly(2).times
      obj.should_receive(:<).exactly(2).times
      (1..3).max {|a,b| obj }
    end

    it "returns the element the block determines to be the maximum" do
      (1..3).max {|a,b| -3 }.should == 1
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/range/max_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/range/max_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/range/max_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/range/max_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/range/max_spec.rb