Sha256: e55120d492dd223beb19f63c35fef848edd3c10a79e0f328cf5b840d9a62c3d3

Contents?: true

Size: 1.63 KB

Versions: 19

Compression:

Stored size: 1.63 KB

Contents

require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/../../spec_helper'
require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/fixtures/classes'

describe "Math.ldexp" do
  it "returns a float" do
    Math.ldexp(1.0, 2).class.should == Float
  end
  
  it "returns the argument multiplied by 2**n" do
    Math.ldexp(0.0, 0.0).should == 0.0
    Math.ldexp(0.0, 1.0).should == 0.0
    Math.ldexp(-1.25, 2).should be_close(-5.0, TOLERANCE)
    Math.ldexp(2.1, -3).should be_close(0.2625, TOLERANCE)
    Math.ldexp(5.7, 4).should be_close(91.2, TOLERANCE)
  end

  it "raises an ArgumentError if the first argument cannot be coerced with Float()" do    
    lambda { Math.ldexp("test", 2) }.should raise_error(ArgumentError)
  end
  
  it "raises an TypeError if the second argument cannot be coerced with Integer()" do
    lambda { Math.ldexp(3.2, "this") }.should raise_error(TypeError)
  end
  
  it "raises a TypeError if the first argument is nil" do
    lambda { Math.ldexp(nil, 2) }.should raise_error(TypeError)
  end
  
  it "raises a TypeError if the second argument is nil" do
    lambda { Math.ldexp(3.1, nil) }.should raise_error(TypeError)
  end
  
  it "accepts any first argument that can be coerced with Float()" do
    Math.ldexp(MathSpecs::Float.new, 2).should be_close(4.0, TOLERANCE)
  end
  
  it "accepts any second argument that can be coerced with Integer()" do
    Math.ldexp(3.23, MathSpecs::Integer.new).should be_close(12.92, TOLERANCE)
  end
end

describe "Math#ldexp" do
  it "is accessible as a private instance method" do
    IncludesMath.new.send(:ldexp, 3.1415, 2).should be_close(12.566, TOLERANCE)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
rhodes-2.0.0.beta11 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-2.0.0.beta10 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-2.0.0.beta9 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-2.0.0.beta8 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-2.0.0.beta7 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-2.0.0.beta6 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-2.0.0.beta4 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-2.0.0.beta3 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-1.5.5 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-2.0.0.beta2 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-2.0.0.beta1 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-1.5.4 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-1.5.3 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-1.5.2 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-1.5.1 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-1.5.0 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-1.4.2 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-1.4.1 spec/framework_spec/app/spec/core/math/ldexp_spec.rb
rhodes-1.4.0 spec/framework_spec/app/spec/core/math/ldexp_spec.rb