mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
58
spec/ruby/core/math/acos_spec.rb
Normal file
58
spec/ruby/core/math/acos_spec.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
# arccosine : (-1.0, 1.0) --> (0, PI)
|
||||
describe "Math.acos" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "returns a float" do
|
||||
Math.acos(1).should be_kind_of(Float )
|
||||
end
|
||||
|
||||
it "returns the arccosine of the argument" do
|
||||
Math.acos(1).should be_close(0.0, TOLERANCE)
|
||||
Math.acos(0).should be_close(1.5707963267949, TOLERANCE)
|
||||
Math.acos(-1).should be_close(Math::PI,TOLERANCE)
|
||||
Math.acos(0.25).should be_close(1.31811607165282, TOLERANCE)
|
||||
Math.acos(0.50).should be_close(1.0471975511966 , TOLERANCE)
|
||||
Math.acos(0.75).should be_close(0.722734247813416, TOLERANCE)
|
||||
end
|
||||
|
||||
conflicts_with :Complex do
|
||||
it "raises an Errno::EDOM if the argument is greater than 1.0" do
|
||||
lambda { Math.acos(1.0001) }.should raise_error(Errno::EDOM)
|
||||
end
|
||||
|
||||
it "raises an Errno::EDOM if the argument is less than -1.0" do
|
||||
lambda { Math.acos(-1.0001) }.should raise_error(Errno::EDOM)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises a TypeError if the string argument cannot be coerced with Float()" do
|
||||
lambda { Math.acos("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.acos(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.acos(MathSpecs::UserClass.new) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.acos(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.acos(MathSpecs::Float.new(0.5)).should be_close(Math.acos(0.5), TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#acos" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:acos, 0).should be_close(1.5707963267949, TOLERANCE)
|
||||
end
|
||||
end
|
43
spec/ruby/core/math/acosh_spec.rb
Normal file
43
spec/ruby/core/math/acosh_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.acosh" do
|
||||
it "returns a float" do
|
||||
Math.acosh(1.0).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the principle value of the inverse hyperbolic cosine of the argument" do
|
||||
Math.acosh(14.2).should be_close(3.345146999647, TOLERANCE)
|
||||
Math.acosh(1.0).should be_close(0.0, TOLERANCE)
|
||||
end
|
||||
|
||||
conflicts_with :Complex do
|
||||
it "raises Errno::EDOM if the passed argument is less than -1.0 or greater than 1.0" do
|
||||
lambda { Math.acosh(1.0 - TOLERANCE) }.should raise_error(Errno::EDOM)
|
||||
lambda { Math.acosh(0) }.should raise_error(Errno::EDOM)
|
||||
lambda { Math.acosh(-1.0) }.should raise_error(Errno::EDOM)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.acosh("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.acosh(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.acosh(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.acosh(MathSpecs::Float.new).should == 0.0
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#acosh" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:acosh, 1.0).should be_close(0.0, TOLERANCE)
|
||||
end
|
||||
end
|
50
spec/ruby/core/math/asin_spec.rb
Normal file
50
spec/ruby/core/math/asin_spec.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
# arcsine : (-1.0, 1.0) --> (-PI/2, PI/2)
|
||||
describe "Math.asin" do
|
||||
it "returns a float" do
|
||||
Math.asin(1).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the arcsine of the argument" do
|
||||
Math.asin(1).should be_close(Math::PI/2, TOLERANCE)
|
||||
Math.asin(0).should be_close(0.0, TOLERANCE)
|
||||
Math.asin(-1).should be_close(-Math::PI/2, TOLERANCE)
|
||||
Math.asin(0.25).should be_close(0.252680255142079, TOLERANCE)
|
||||
Math.asin(0.50).should be_close(0.523598775598299, TOLERANCE)
|
||||
Math.asin(0.75).should be_close(0.8480620789814816,TOLERANCE)
|
||||
end
|
||||
|
||||
conflicts_with :Complex do
|
||||
it "raises an Errno::EDOM if the argument is greater than 1.0" do
|
||||
lambda { Math.asin(1.0001) }.should raise_error( Errno::EDOM)
|
||||
end
|
||||
|
||||
it "raises an Errno::EDOM if the argument is less than -1.0" do
|
||||
lambda { Math.asin(-1.0001) }.should raise_error( Errno::EDOM)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.asin("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.asin(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.asin(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.asin(MathSpecs::Float.new).should be_close(1.5707963267949, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#asin" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:asin, 0.5).should be_close(0.523598775598299, TOLERANCE)
|
||||
end
|
||||
end
|
42
spec/ruby/core/math/asinh_spec.rb
Normal file
42
spec/ruby/core/math/asinh_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.asinh" do
|
||||
it "returns a float" do
|
||||
Math.asinh(1.5).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the inverse hyperbolic sin of the argument" do
|
||||
Math.asinh(1.5).should be_close(1.19476321728711, TOLERANCE)
|
||||
Math.asinh(-2.97).should be_close(-1.8089166921397, TOLERANCE)
|
||||
Math.asinh(0.0).should == 0.0
|
||||
Math.asinh(-0.0).should == -0.0
|
||||
Math.asinh(1.05367e-08).should be_close(1.05367e-08, TOLERANCE)
|
||||
Math.asinh(-1.05367e-08).should be_close(-1.05367e-08, TOLERANCE)
|
||||
# Default tolerance does not scale right for these...
|
||||
#Math.asinh(94906265.62).should be_close(19.0615, TOLERANCE)
|
||||
#Math.asinh(-94906265.62).should be_close(-19.0615, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.asinh("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.asinh(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.asinh(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.asinh(MathSpecs::Float.new).should be_close(0.881373587019543, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#asinh" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:asinh, 19.275).should be_close(3.65262832292466, TOLERANCE)
|
||||
end
|
||||
end
|
54
spec/ruby/core/math/atan2_spec.rb
Normal file
54
spec/ruby/core/math/atan2_spec.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.atan2" do
|
||||
it "returns a float" do
|
||||
Math.atan2(1.2, 0.5).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the arc tangent of y, x" do
|
||||
Math.atan2(4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
|
||||
Math.atan2(0.0, 1.0).should be_close(0.0, TOLERANCE)
|
||||
Math.atan2(-9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
|
||||
Math.atan2(7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.atan2(1.0, "test") }.should raise_error(TypeError)
|
||||
lambda { Math.atan2("test", 0.0) }.should raise_error(TypeError)
|
||||
lambda { Math.atan2("test", "this") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.atan2(nil, 1.0) }.should raise_error(TypeError)
|
||||
lambda { Math.atan2(-1.0, nil) }.should raise_error(TypeError)
|
||||
lambda { Math.atan2(nil, nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.atan2(MathSpecs::Float.new, MathSpecs::Float.new).should be_close(0.785398163397448, TOLERANCE)
|
||||
end
|
||||
|
||||
it "returns positive zero when passed 0.0, 0.0" do
|
||||
Math.atan2(0.0, 0.0).should be_positive_zero
|
||||
end
|
||||
|
||||
it "returns negative zero when passed -0.0, 0.0" do
|
||||
Math.atan2(-0.0, 0.0).should be_negative_zero
|
||||
end
|
||||
|
||||
it "returns Pi when passed 0.0, -0.0" do
|
||||
Math.atan2(0.0, -0.0).should == Math::PI
|
||||
end
|
||||
|
||||
it "returns -Pi when passed -0.0, -0.0" do
|
||||
Math.atan2(-0.0, -0.0).should == -Math::PI
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Math#atan2" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:atan2, 1.1, 2.2).should be_close(0.463647609000806, TOLERANCE)
|
||||
end
|
||||
end
|
40
spec/ruby/core/math/atan_spec.rb
Normal file
40
spec/ruby/core/math/atan_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
# arctangent : (-Inf, Inf) --> (-PI/2, PI/2)
|
||||
describe "Math.atan" do
|
||||
it "returns a float" do
|
||||
Math.atan(1).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the arctangent of the argument" do
|
||||
Math.atan(1).should be_close(Math::PI/4, TOLERANCE)
|
||||
Math.atan(0).should be_close(0.0, TOLERANCE)
|
||||
Math.atan(-1).should be_close(-Math::PI/4, TOLERANCE)
|
||||
Math.atan(0.25).should be_close(0.244978663126864, TOLERANCE)
|
||||
Math.atan(0.50).should be_close(0.463647609000806, TOLERANCE)
|
||||
Math.atan(0.75).should be_close(0.643501108793284, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.atan("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.atan(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.atan(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.atan(MathSpecs::Float.new).should be_close(0.785398163397448, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#atan" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:atan, 3.1415).should be_close(1.2626187313511, TOLERANCE)
|
||||
end
|
||||
end
|
14
spec/ruby/core/math/atanh_spec.rb
Normal file
14
spec/ruby/core/math/atanh_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../../fixtures/math/common', __FILE__)
|
||||
require File.expand_path('../../../shared/math/atanh', __FILE__)
|
||||
|
||||
describe "Math.atanh" do
|
||||
it_behaves_like :math_atanh_base, :atanh, Math
|
||||
it_behaves_like :math_atanh_no_complex, :atanh, Math
|
||||
end
|
||||
|
||||
describe "Math#atanh" do
|
||||
it_behaves_like :math_atanh_private, :atanh
|
||||
it_behaves_like :math_atanh_base, :atanh, IncludesMath.new
|
||||
it_behaves_like :math_atanh_no_complex, :atanh, IncludesMath.new
|
||||
end
|
27
spec/ruby/core/math/cbrt_spec.rb
Normal file
27
spec/ruby/core/math/cbrt_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.cbrt" do
|
||||
it "returns a float" do
|
||||
Math.cbrt(1).should be_an_instance_of(Float)
|
||||
end
|
||||
|
||||
it "returns the cubic root of the argument" do
|
||||
Math.cbrt(1).should == 1.0
|
||||
Math.cbrt(8.0).should == 2.0
|
||||
Math.cbrt(-8.0).should == -2.0
|
||||
Math.cbrt(3).should be_close(1.44224957030741, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.cbrt("foobar") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.cbrt(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.cbrt(MathSpecs::Float.new).should be_close(1.0, TOLERANCE)
|
||||
end
|
||||
end
|
22
spec/ruby/core/math/constants_spec.rb
Normal file
22
spec/ruby/core/math/constants_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math::PI" do
|
||||
it "approximates the value of pi" do
|
||||
Math::PI.should be_close(3.14159_26535_89793_23846, TOLERANCE)
|
||||
end
|
||||
|
||||
it "is accessible to a class that includes Math" do
|
||||
IncludesMath::PI.should == Math::PI
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math::E" do
|
||||
it "approximates the value of Napier's constant" do
|
||||
Math::E.should be_close(2.71828_18284_59045_23536, TOLERANCE)
|
||||
end
|
||||
|
||||
it "is accessible to a class that includes Math" do
|
||||
IncludesMath::E.should == Math::E
|
||||
end
|
||||
end
|
42
spec/ruby/core/math/cos_spec.rb
Normal file
42
spec/ruby/core/math/cos_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
# cosine : (-Inf, Inf) --> (-1.0, 1.0)
|
||||
describe "Math.cos" do
|
||||
it "returns a float" do
|
||||
Math.cos(Math::PI).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the cosine of the argument expressed in radians" do
|
||||
Math.cos(Math::PI).should be_close(-1.0, TOLERANCE)
|
||||
Math.cos(0).should be_close(1.0, TOLERANCE)
|
||||
Math.cos(Math::PI/2).should be_close(0.0, TOLERANCE)
|
||||
Math.cos(3*Math::PI/2).should be_close(0.0, TOLERANCE)
|
||||
Math.cos(2*Math::PI).should be_close(1.0, TOLERANCE)
|
||||
end
|
||||
|
||||
|
||||
it "raises a TypeError unless the argument is Numeric and has #to_f" do
|
||||
lambda { Math.cos("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.cos(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.cos(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "coerces its argument with #to_f" do
|
||||
f = mock_numeric('8.2')
|
||||
f.should_receive(:to_f).and_return(8.2)
|
||||
Math.cos(f).should == Math.cos(8.2)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#cos" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:cos, 3.1415).should be_close(-0.999999995707656, TOLERANCE)
|
||||
end
|
||||
end
|
37
spec/ruby/core/math/cosh_spec.rb
Normal file
37
spec/ruby/core/math/cosh_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.cosh" do
|
||||
it "returns a float" do
|
||||
Math.cosh(1.0).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the hyperbolic cosine of the argument" do
|
||||
Math.cosh(0.0).should == 1.0
|
||||
Math.cosh(-0.0).should == 1.0
|
||||
Math.cosh(1.5).should be_close(2.35240961524325, TOLERANCE)
|
||||
Math.cosh(-2.99).should be_close(9.96798496414416, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.cosh("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.cosh(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.cosh(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.cosh(MathSpecs::Float.new).should be_close(1.54308063481524, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#cosh" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:cos, 3.1415).should be_close(-0.999999995707656, TOLERANCE)
|
||||
end
|
||||
end
|
44
spec/ruby/core/math/erf_spec.rb
Normal file
44
spec/ruby/core/math/erf_spec.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
# erf method is the "error function" encountered in integrating the normal
|
||||
# distribution (which is a normalized form of the Gaussian function).
|
||||
describe "Math.erf" do
|
||||
it "returns a float" do
|
||||
Math.erf(1).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the error function of the argument" do
|
||||
Math.erf(0).should be_close(0.0, TOLERANCE)
|
||||
Math.erf(1).should be_close(0.842700792949715, TOLERANCE)
|
||||
Math.erf(-1).should be_close(-0.842700792949715, TOLERANCE)
|
||||
Math.erf(0.5).should be_close(0.520499877813047, TOLERANCE)
|
||||
Math.erf(-0.5).should be_close(-0.520499877813047, TOLERANCE)
|
||||
Math.erf(10000).should be_close(1.0, TOLERANCE)
|
||||
Math.erf(-10000).should be_close(-1.0, TOLERANCE)
|
||||
Math.erf(0.00000000000001).should be_close(0.0, TOLERANCE)
|
||||
Math.erf(-0.00000000000001).should be_close(0.0, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.erf("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.erf(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.erf(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.erf(MathSpecs::Float.new).should be_close(0.842700792949715, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#erf" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:erf, 3.1415).should be_close(0.999991118444483, TOLERANCE)
|
||||
end
|
||||
end
|
43
spec/ruby/core/math/erfc_spec.rb
Normal file
43
spec/ruby/core/math/erfc_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
# erfc is the complementary error function
|
||||
describe "Math.erfc" do
|
||||
it "returns a float" do
|
||||
Math.erf(1).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the complementary error function of the argument" do
|
||||
Math.erfc(0).should be_close(1.0, TOLERANCE)
|
||||
Math.erfc(1).should be_close(0.157299207050285, TOLERANCE)
|
||||
Math.erfc(-1).should be_close(1.84270079294971, TOLERANCE)
|
||||
Math.erfc(0.5).should be_close(0.479500122186953, TOLERANCE)
|
||||
Math.erfc(-0.5).should be_close(1.52049987781305, TOLERANCE)
|
||||
Math.erfc(10000).should be_close(0.0, TOLERANCE)
|
||||
Math.erfc(-10000).should be_close(2.0, TOLERANCE)
|
||||
Math.erfc(0.00000000000001).should be_close(0.999999999999989, TOLERANCE)
|
||||
Math.erfc(-0.00000000000001).should be_close(1.00000000000001, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.erfc("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.erfc(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.erfc(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.erfc(MathSpecs::Float.new).should be_close(0.157299207050285, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#erfc" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:erf, 3.1415).should be_close(0.999991118444483, TOLERANCE)
|
||||
end
|
||||
end
|
37
spec/ruby/core/math/exp_spec.rb
Normal file
37
spec/ruby/core/math/exp_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.exp" do
|
||||
it "returns a float" do
|
||||
Math.exp(1.0).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the base-e exponential of the argument" do
|
||||
Math.exp(0.0).should == 1.0
|
||||
Math.exp(-0.0).should == 1.0
|
||||
Math.exp(-1.8).should be_close(0.165298888221587, TOLERANCE)
|
||||
Math.exp(1.25).should be_close(3.49034295746184, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.exp("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.exp(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.exp(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.exp(MathSpecs::Float.new).should be_close(Math::E, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#exp" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:exp, 23.1415).should be_close(11226018484.0012, TOLERANCE)
|
||||
end
|
||||
end
|
28
spec/ruby/core/math/fixtures/classes.rb
Normal file
28
spec/ruby/core/math/fixtures/classes.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
class IncludesMath
|
||||
include Math
|
||||
end
|
||||
|
||||
module MathSpecs
|
||||
class Float < Numeric
|
||||
def initialize(value=1.0)
|
||||
@value = value
|
||||
end
|
||||
|
||||
def to_f
|
||||
@value
|
||||
end
|
||||
end
|
||||
|
||||
class Integer
|
||||
def to_int
|
||||
2
|
||||
end
|
||||
end
|
||||
|
||||
class UserClass
|
||||
end
|
||||
|
||||
class StringSubClass < String
|
||||
end
|
||||
|
||||
end
|
37
spec/ruby/core/math/frexp_spec.rb
Normal file
37
spec/ruby/core/math/frexp_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.frexp" do
|
||||
it "returns the normalized fraction and exponent" do
|
||||
frac, exp = Math.frexp(102.83)
|
||||
frac.should be_close(0.803359375, TOLERANCE)
|
||||
exp.should == 7
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.frexp("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
frac, _exp = Math.frexp(nan_value)
|
||||
frac.nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.frexp(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
frac, exp = Math.frexp(MathSpecs::Float.new)
|
||||
frac.should be_close(0.5, TOLERANCE)
|
||||
exp.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#frexp" do
|
||||
it "is accessible as a private instance method" do
|
||||
frac, exp = IncludesMath.new.send(:frexp, 2.1415)
|
||||
frac.should be_close(0.535375, TOLERANCE)
|
||||
exp.should == 2
|
||||
end
|
||||
end
|
69
spec/ruby/core/math/gamma_spec.rb
Normal file
69
spec/ruby/core/math/gamma_spec.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
|
||||
describe "Math.gamma" do
|
||||
it "returns +infinity given 0" do
|
||||
Math.gamma(0).should == Float::INFINITY
|
||||
end
|
||||
|
||||
platform_is_not :windows do
|
||||
# https://bugs.ruby-lang.org/issues/12249
|
||||
it "returns -infinity given -0.0" do
|
||||
Math.gamma(-0.0).should == -Float::INFINITY
|
||||
end
|
||||
end
|
||||
|
||||
it "returns Math.sqrt(Math::PI) given 0.5" do
|
||||
Math.gamma(0.5).should be_close(Math.sqrt(Math::PI), TOLERANCE)
|
||||
end
|
||||
|
||||
# stop at n == 23 because 23! cannot be exactly represented by IEEE 754 double
|
||||
it "returns exactly (n-1)! given n for n between 2 and 23" do
|
||||
fact = 1
|
||||
2.upto(23) do |n|
|
||||
fact *= (n - 1)
|
||||
Math.gamma(n).should == fact
|
||||
end
|
||||
end
|
||||
|
||||
it "returns approximately (n-1)! given n for n between 24 and 30" do
|
||||
fact2 = 1124000727777607680000 # 22!
|
||||
24.upto(30) do |n|
|
||||
fact2 *= n - 1
|
||||
# compare only the first 12 places, tolerate the rest
|
||||
Math.gamma(n).should be_close(fact2, fact2.to_s[12..-1].to_i)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns good numerical approximation for gamma(3.2)" do
|
||||
Math.gamma(3.2).should be_close(2.423965, TOLERANCE)
|
||||
end
|
||||
|
||||
it "returns good numerical approximation for gamma(-2.15)" do
|
||||
Math.gamma(-2.15).should be_close(-2.999619, TOLERANCE)
|
||||
end
|
||||
|
||||
it "returns good numerical approximation for gamma(0.00001)" do
|
||||
Math.gamma(0.00001).should be_close(99999.422794, TOLERANCE)
|
||||
end
|
||||
|
||||
it "returns good numerical approximation for gamma(-0.00001)" do
|
||||
Math.gamma(-0.00001).should be_close(-100000.577225, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises Math::DomainError given -1" do
|
||||
lambda { Math.gamma(-1) }.should raise_error(Math::DomainError)
|
||||
end
|
||||
|
||||
# See https://bugs.ruby-lang.org/issues/10642
|
||||
it "returns +infinity given +infinity" do
|
||||
Math.gamma(infinity_value).infinite?.should == 1
|
||||
end
|
||||
|
||||
it "raises Math::DomainError given negative infinity" do
|
||||
lambda { Math.gamma(-Float::INFINITY) }.should raise_error(Math::DomainError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.gamma(nan_value).nan?.should be_true
|
||||
end
|
||||
end
|
41
spec/ruby/core/math/hypot_spec.rb
Normal file
41
spec/ruby/core/math/hypot_spec.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
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
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.hypot("test", "this") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.hypot(nan_value, 0).nan?.should be_true
|
||||
Math.hypot(0, nan_value).nan?.should be_true
|
||||
Math.hypot(nan_value, nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.hypot(nil, nil) }.should raise_error(TypeError)
|
||||
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
|
54
spec/ruby/core/math/ldexp_spec.rb
Normal file
54
spec/ruby/core/math/ldexp_spec.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.ldexp" do
|
||||
it "returns a float" do
|
||||
Math.ldexp(1.0, 2).should be_kind_of(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 a TypeError if the first argument cannot be coerced with Float()" do
|
||||
lambda { Math.ldexp("test", 2) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.ldexp(nan_value, 0).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises RangeError if NaN is given as the second arg" do
|
||||
lambda { Math.ldexp(0, nan_value) }.should raise_error(RangeError)
|
||||
end
|
||||
|
||||
it "raises a 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
|
56
spec/ruby/core/math/lgamma_spec.rb
Normal file
56
spec/ruby/core/math/lgamma_spec.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
|
||||
describe "Math.lgamma" do
|
||||
it "returns [Infinity, 1] when passed 0" do
|
||||
Math.lgamma(0).should == [infinity_value, 1]
|
||||
end
|
||||
|
||||
platform_is_not :windows do
|
||||
it "returns [Infinity, 1] when passed -1" do
|
||||
Math.lgamma(-1).should == [infinity_value, 1]
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.4" do
|
||||
it "returns [Infinity, -1] when passed -0.0" do
|
||||
Math.lgamma(-0.0).should == [infinity_value, -1]
|
||||
end
|
||||
end
|
||||
|
||||
it "returns [log(sqrt(PI)), 1] when passed 0.5" do
|
||||
lg1 = Math.lgamma(0.5)
|
||||
lg1[0].should be_close(Math.log(Math.sqrt(Math::PI)), TOLERANCE)
|
||||
lg1[1].should == 1
|
||||
end
|
||||
|
||||
it "returns [log(2/3*PI, 1] when passed 6.0" do
|
||||
lg2 = Math.lgamma(6.0)
|
||||
lg2[0].should be_close(Math.log(120.0), TOLERANCE)
|
||||
lg2[1].should == 1
|
||||
end
|
||||
|
||||
it "returns an approximate value when passed -0.5" do
|
||||
lg1 = Math.lgamma(-0.5)
|
||||
lg1[0].should be_close(1.2655121, TOLERANCE)
|
||||
lg1[1].should == -1
|
||||
end
|
||||
|
||||
it "returns an approximate value when passed -1.5" do
|
||||
lg2 = Math.lgamma(-1.5)
|
||||
lg2[0].should be_close(0.8600470, TOLERANCE)
|
||||
lg2[1].should == 1
|
||||
end
|
||||
|
||||
it "raises Math::DomainError when passed -Infinity" do
|
||||
lambda { Math.lgamma(-infinity_value) }.should raise_error(Math::DomainError)
|
||||
end
|
||||
|
||||
it "returns [Infinity, 1] when passed Infinity" do
|
||||
Math.lgamma(infinity_value).should == [infinity_value, 1]
|
||||
end
|
||||
|
||||
it "returns [NaN, 1] when passed NaN" do
|
||||
Math.lgamma(nan_value)[0].nan?.should be_true
|
||||
Math.lgamma(nan_value)[1].should == 1
|
||||
end
|
||||
end
|
45
spec/ruby/core/math/log10_spec.rb
Normal file
45
spec/ruby/core/math/log10_spec.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
# The common logarithm, having base 10
|
||||
describe "Math.log10" do
|
||||
it "returns a float" do
|
||||
Math.log10(1).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the base-10 logarithm of the argument" do
|
||||
Math.log10(0.0001).should be_close(-4.0, TOLERANCE)
|
||||
Math.log10(0.000000000001e-15).should be_close(-27.0, TOLERANCE)
|
||||
Math.log10(1).should be_close(0.0, TOLERANCE)
|
||||
Math.log10(10).should be_close(1.0, TOLERANCE)
|
||||
Math.log10(10e15).should be_close(16.0, TOLERANCE)
|
||||
end
|
||||
|
||||
conflicts_with :Complex do
|
||||
it "raises an Errno::EDOM if the argument is less than 0" do
|
||||
lambda { Math.log10(-1e-15) }.should raise_error( Errno::EDOM)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.log10("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.log10(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.log10(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.log10(MathSpecs::Float.new).should be_close(0.0, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#log10" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:log10, 4.15).should be_close(0.618048096712093, TOLERANCE)
|
||||
end
|
||||
end
|
41
spec/ruby/core/math/log2_spec.rb
Normal file
41
spec/ruby/core/math/log2_spec.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.log2" do
|
||||
it "returns a float" do
|
||||
Math.log2(5.79).should be_close(2.53356334821451, TOLERANCE)
|
||||
end
|
||||
|
||||
it "returns the natural logarithm of the argument" do
|
||||
Math.log2(1.1).should be_close(0.137503523749935, TOLERANCE)
|
||||
Math.log2(3.14).should be_close(1.6507645591169, TOLERANCE)
|
||||
Math.log2((2**101+45677544234809571)).should be_close(101.00000000000003, TOLERANCE)
|
||||
|
||||
Math.log2((2**10001+45677544234809571)).should == 10001.0
|
||||
Math.log2((2**301+45677544234809571)).should == 301.0
|
||||
end
|
||||
|
||||
it "raises an Errno::EDOM if the argument is less than 0" do
|
||||
lambda { Math.log2(-1e-15) }.should raise_error( Math::DomainError)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.log2("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError if passed a numerical argument as a string" do
|
||||
lambda { Math.log2("1.0") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.log2(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.log2(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.log2(MathSpecs::Float.new).should be_close(0.0, TOLERANCE)
|
||||
end
|
||||
end
|
59
spec/ruby/core/math/log_spec.rb
Normal file
59
spec/ruby/core/math/log_spec.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
# The natural logarithm, having base Math::E
|
||||
describe "Math.log" do
|
||||
it "returns a float" do
|
||||
Math.log(1).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the natural logarithm of the argument" do
|
||||
Math.log(0.0001).should be_close(-9.21034037197618, TOLERANCE)
|
||||
Math.log(0.000000000001e-15).should be_close(-62.1697975108392, TOLERANCE)
|
||||
Math.log(1).should be_close(0.0, TOLERANCE)
|
||||
Math.log(10).should be_close( 2.30258509299405, TOLERANCE)
|
||||
Math.log(10e15).should be_close(36.8413614879047, TOLERANCE)
|
||||
end
|
||||
|
||||
conflicts_with :Complex do
|
||||
it "raises an Errno::EDOM if the argument is less than 0" do
|
||||
lambda { Math.log(-1e-15) }.should raise_error(Errno::EDOM)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.log("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError for numerical values passed as string" do
|
||||
lambda { Math.log("10") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts a second argument for the base" do
|
||||
Math.log(9, 3).should be_close(2, TOLERANCE)
|
||||
Math.log(8, 1.4142135623730951).should be_close(6, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError when the numerical base cannot be coerced to a float" do
|
||||
lambda { Math.log(10, "2") }.should raise_error(TypeError)
|
||||
lambda { Math.log(10, nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.log(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.log(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.log(MathSpecs::Float.new).should be_close(0.0, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#log" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:log, 5.21).should be_close(1.65057985576528, TOLERANCE)
|
||||
end
|
||||
end
|
39
spec/ruby/core/math/sin_spec.rb
Normal file
39
spec/ruby/core/math/sin_spec.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
# sine : (-Inf, Inf) --> (-1.0, 1.0)
|
||||
describe "Math.sin" do
|
||||
it "returns a float" do
|
||||
Math.sin(Math::PI).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the sine of the argument expressed in radians" do
|
||||
Math.sin(Math::PI).should be_close(0.0, TOLERANCE)
|
||||
Math.sin(0).should be_close(0.0, TOLERANCE)
|
||||
Math.sin(Math::PI/2).should be_close(1.0, TOLERANCE)
|
||||
Math.sin(3*Math::PI/2).should be_close(-1.0, TOLERANCE)
|
||||
Math.sin(2*Math::PI).should be_close(0.0, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.sin("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.sin(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.sin(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.sin(MathSpecs::Float.new).should be_close(0.841470984807897, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#sin" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:sin, 1.21).should be_close(0.935616001553386, TOLERANCE)
|
||||
end
|
||||
end
|
37
spec/ruby/core/math/sinh_spec.rb
Normal file
37
spec/ruby/core/math/sinh_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.sinh" do
|
||||
it "returns a float" do
|
||||
Math.sinh(1.2).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the hyperbolic sin of the argument" do
|
||||
Math.sinh(0.0).should == 0.0
|
||||
Math.sinh(-0.0).should == 0.0
|
||||
Math.sinh(1.5).should be_close(2.12927945509482, TOLERANCE)
|
||||
Math.sinh(-2.8).should be_close(-8.19191835423591, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.sinh("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.sinh(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.sinh(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.sinh(MathSpecs::Float.new).should be_close(1.1752011936438, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#sinh" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:sinh, 1.99).should be_close(3.58941916843202, TOLERANCE)
|
||||
end
|
||||
end
|
36
spec/ruby/core/math/sqrt_spec.rb
Normal file
36
spec/ruby/core/math/sqrt_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.sqrt" do
|
||||
it "returns a float" do
|
||||
Math.sqrt(1).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the square root of the argument" do
|
||||
Math.sqrt(1).should == 1.0
|
||||
Math.sqrt(4.0).should == 2.0
|
||||
Math.sqrt(15241578780673814.441547445).should be_close(123456789.123457, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.sqrt("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.sqrt(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.sqrt(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.sqrt(MathSpecs::Float.new).should be_close(1.0, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#sqrt" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:sqrt, 2.23).should be_close(1.49331845230681, TOLERANCE)
|
||||
end
|
||||
end
|
42
spec/ruby/core/math/tan_spec.rb
Normal file
42
spec/ruby/core/math/tan_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.tan" do
|
||||
it "returns a float" do
|
||||
Math.tan(1.35).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the tangent of the argument" do
|
||||
Math.tan(0.0).should == 0.0
|
||||
Math.tan(-0.0).should == -0.0
|
||||
Math.tan(4.22).should be_close(1.86406937682395, TOLERANCE)
|
||||
Math.tan(-9.65).should be_close(-0.229109052606441, TOLERANCE)
|
||||
end
|
||||
|
||||
it "returns NaN if called with +-Infinitty" do
|
||||
Math.tan(infinity_value).nan?.should == true
|
||||
Math.tan(-infinity_value).nan?.should == true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.tan("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.tan(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.tan(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.tan(MathSpecs::Float.new).should be_close(1.5574077246549, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#tan" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:tan, 1.0).should be_close(1.5574077246549, TOLERANCE)
|
||||
end
|
||||
end
|
39
spec/ruby/core/math/tanh_spec.rb
Normal file
39
spec/ruby/core/math/tanh_spec.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "Math.tanh" do
|
||||
it "returns a float" do
|
||||
Math.tanh(0.5).should be_kind_of(Float)
|
||||
end
|
||||
|
||||
it "returns the hyperbolic tangent of the argument" do
|
||||
Math.tanh(0.0).should == 0.0
|
||||
Math.tanh(-0.0).should == -0.0
|
||||
Math.tanh(infinity_value).should == 1.0
|
||||
Math.tanh(-infinity_value).should == -1.0
|
||||
Math.tanh(2.5).should be_close(0.98661429815143, TOLERANCE)
|
||||
Math.tanh(-4.892).should be_close(-0.999887314427707, TOLERANCE)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument cannot be coerced with Float()" do
|
||||
lambda { Math.tanh("test") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns NaN given NaN" do
|
||||
Math.tanh(nan_value).nan?.should be_true
|
||||
end
|
||||
|
||||
it "raises a TypeError if the argument is nil" do
|
||||
lambda { Math.tanh(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "accepts any argument that can be coerced with Float()" do
|
||||
Math.tanh(MathSpecs::Float.new).should be_close(0.761594155955765, TOLERANCE)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Math#tanh" do
|
||||
it "is accessible as a private instance method" do
|
||||
IncludesMath.new.send(:tanh, 5.21).should be_close(0.99994034202065, TOLERANCE)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue