Sha256: f4b1186ec63ba49b4779a9b6e452ce012596cda29cfdc5d17b49df4cd1eed9fb

Contents?: true

Size: 1.43 KB

Versions: 52

Compression:

Stored size: 1.43 KB

Contents

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

describe "Fixnum#quo" do
  it "returns the result of self divided by the given Integer as a Float" do
    2.quo(2.5).should == 0.8
    5.quo(2).should == 2.5
    45.quo(bignum_value).should be_close(1.04773789668636e-08, TOLERANCE)
  end

  ruby_version_is ""..."1.9" do
    conflicts_with :Rational do
      it "does not raise a ZeroDivisionError when the given Integer is 0" do
        0.quo(0).to_s.should == "NaN"
        10.quo(0).to_s.should == "Infinity"
        -10.quo(0).to_s.should == "-Infinity"
      end
    end
  end

  ruby_version_is "1.9" do
    it "raises a ZeroDivisionError when the given Integer is 0" do
      lambda { 0.quo(0) }.should raise_error(ZeroDivisionError)
      lambda { 10.quo(0) }.should raise_error(ZeroDivisionError)
      lambda { -10.quo(0) }.should raise_error(ZeroDivisionError)
    end
  end

  it "does not raise a FloatDomainError when the given Integer is 0 and a Float" do
    0.quo(0.0).to_s.should == "NaN"
    10.quo(0.0).to_s.should == "Infinity"
    -10.quo(0.0).to_s.should == "-Infinity"
  end

  conflicts_with :Rational do
    it "raises a TypeError when given a non-Integer" do
      lambda {
        (obj = mock('x')).should_not_receive(:to_int)
        13.quo(obj)
      }.should raise_error(TypeError)
      lambda { 13.quo("10")    }.should raise_error(TypeError)
      lambda { 13.quo(:symbol) }.should raise_error(TypeError)
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-3.2.2 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.2.beta spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.1 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.0 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.0.beta.9 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.0.beta.8 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.0.beta.7 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.0.beta.6 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.0.beta.5 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.0.beta.4 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.0.beta.2 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb
rhodes-3.2.0.beta.1 spec/framework_spec/app/spec/core/fixnum/quo_spec.rb