Sha256: c574f9f9956375aaa1c176c7b7d24932250c6d18ebbc983e942cac0708f9c909

Contents?: true

Size: 1.24 KB

Versions: 52

Compression:

Stored size: 1.24 KB

Contents

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

describe "Integer#round" do
  it_behaves_like(:integer_to_i, :round)

  ruby_version_is "1.9" do
    it "rounds itself as a float if passed a positive precision" do
      [2, -4, 10**70, -10**100].each do |v|
        v.round(42).should eql(v.to_f)
      end
    end

    it "returns itself if passed zero" do
      [2, -4, 10**70, -10**100].each do |v|
        v.round(0).should eql(v)
      end
    end

    ruby_bug "redmine:5228", "1.9.2" do
      it "returns itself rounded if passed a negative value" do
        +249.round(-2).should eql(+200)
        +250.round(-2).should eql(+300)
        -249.round(-2).should eql(-200)
        -250.round(-2).should eql(-300)
        (+25 * 10**70).round(-71).should eql(+30 * 10**70)
        (-25 * 10**70).round(-71).should eql(-30 * 10**70)
        (+25 * 10**70 - 1).round(-71).should eql(+20 * 10**70)
        (-25 * 10**70 + 1).round(-71).should eql(-20 * 10**70)
      end
    end

    it "raises a TypeError when its argument can not be converted to an Integer" do
      lambda { 42.round("4") }.should raise_error(TypeError)
      lambda { 42.round(nil) }.should raise_error(TypeError)
    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/integer/round_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/integer/round_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/integer/round_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/integer/round_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/integer/round_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/integer/round_spec.rb