Sha256: dd4b31a0b51e0d1e52efe02718ad6f49d6ba1f5d62928eff1d3d3cf09c0f9d7b

Contents?: true

Size: 1.59 KB

Versions: 52

Compression:

Stored size: 1.59 KB

Contents

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

describe "Math.hypot" do
  it "returns a float" do
    Math.hypot(3, 4).should be_kind_of(Float)
  end

  it "returns the length of the hypotenuse of a right triangle with legs given by the arguments" do
    Math.hypot(0, 0).should be_close(0.0, TOLERANCE)
    Math.hypot(2, 10).should be_close( 10.1980390271856, TOLERANCE)
    Math.hypot(5000, 5000).should be_close(7071.06781186548, TOLERANCE)
    Math.hypot(0.0001, 0.0002).should be_close(0.000223606797749979, TOLERANCE)
    Math.hypot(-2, -10).should be_close(10.1980390271856, TOLERANCE)
    Math.hypot(2, 10).should be_close(10.1980390271856, TOLERANCE)
  end

  ruby_version_is ""..."1.9" do
    it "raises an ArgumentError if the argument cannot be coerced with Float()" do
      lambda { Math.hypot("test", "this") }.should raise_error(ArgumentError)
    end
  end

  ruby_version_is "1.9" do
    it "raises a TypeError if the argument cannot be coerced with Float()" do
      lambda { Math.hypot("test", "this") }.should raise_error(TypeError)
    end
  end

  it "raises a ArgumentError if the argument is nil" do
    lambda { Math.hypot(nil) }.should raise_error(ArgumentError)
  end

  it "accepts any argument that can be coerced with Float()" do
    Math.hypot(MathSpecs::Float.new, MathSpecs::Float.new).should be_close(1.4142135623731, TOLERANCE)
  end
end

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

Version data entries

52 entries across 52 versions & 2 rubygems

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