summaryrefslogtreecommitdiff
path: root/spec/ruby/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/math')
-rw-r--r--spec/ruby/core/math/acos_spec.rb14
-rw-r--r--spec/ruby/core/math/acosh_spec.rb14
-rw-r--r--spec/ruby/core/math/asin_spec.rb12
-rw-r--r--spec/ruby/core/math/asinh_spec.rb8
-rw-r--r--spec/ruby/core/math/atan2_spec.rb14
-rw-r--r--spec/ruby/core/math/atan_spec.rb8
-rw-r--r--spec/ruby/core/math/cbrt_spec.rb6
-rw-r--r--spec/ruby/core/math/cos_spec.rb12
-rw-r--r--spec/ruby/core/math/cosh_spec.rb8
-rw-r--r--spec/ruby/core/math/erf_spec.rb8
-rw-r--r--spec/ruby/core/math/erfc_spec.rb8
-rw-r--r--spec/ruby/core/math/exp_spec.rb8
-rw-r--r--spec/ruby/core/math/expm1_spec.rb37
-rw-r--r--spec/ruby/core/math/frexp_spec.rb6
-rw-r--r--spec/ruby/core/math/gamma_spec.rb6
-rw-r--r--spec/ruby/core/math/hypot_spec.rb12
-rw-r--r--spec/ruby/core/math/ldexp_spec.rb14
-rw-r--r--spec/ruby/core/math/lgamma_spec.rb13
-rw-r--r--spec/ruby/core/math/log10_spec.rb14
-rw-r--r--spec/ruby/core/math/log1p_spec.rb49
-rw-r--r--spec/ruby/core/math/log2_spec.rb10
-rw-r--r--spec/ruby/core/math/log_spec.rb16
-rw-r--r--spec/ruby/core/math/shared/atanh.rb12
-rw-r--r--spec/ruby/core/math/sin_spec.rb8
-rw-r--r--spec/ruby/core/math/sinh_spec.rb8
-rw-r--r--spec/ruby/core/math/sqrt_spec.rb10
-rw-r--r--spec/ruby/core/math/tan_spec.rb8
-rw-r--r--spec/ruby/core/math/tanh_spec.rb8
28 files changed, 219 insertions, 132 deletions
diff --git a/spec/ruby/core/math/acos_spec.rb b/spec/ruby/core/math/acos_spec.rb
index 8b321ab29b..4649dc527c 100644
--- a/spec/ruby/core/math/acos_spec.rb
+++ b/spec/ruby/core/math/acos_spec.rb
@@ -8,7 +8,7 @@ describe "Math.acos" do
end
it "returns a float" do
- Math.acos(1).should be_kind_of(Float )
+ Math.acos(1).should.is_a?(Float )
end
it "returns the arccosine of the argument" do
@@ -21,27 +21,27 @@ describe "Math.acos" do
end
it "raises an Math::DomainError if the argument is greater than 1.0" do
- -> { Math.acos(1.0001) }.should raise_error(Math::DomainError)
+ -> { Math.acos(1.0001) }.should.raise(Math::DomainError)
end
it "raises an Math::DomainError if the argument is less than -1.0" do
- -> { Math.acos(-1.0001) }.should raise_error(Math::DomainError)
+ -> { Math.acos(-1.0001) }.should.raise(Math::DomainError)
end
it "raises a TypeError if the string argument cannot be coerced with Float()" do
- -> { Math.acos("test") }.should raise_error(TypeError)
+ -> { Math.acos("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.acos(nan_value).nan?.should be_true
+ Math.acos(nan_value).nan?.should == true
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.acos(MathSpecs::UserClass.new) }.should raise_error(TypeError)
+ -> { Math.acos(MathSpecs::UserClass.new) }.should.raise(TypeError)
end
it "raises a TypeError if the argument is nil" do
- -> { Math.acos(nil) }.should raise_error(TypeError)
+ -> { Math.acos(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/acosh_spec.rb b/spec/ruby/core/math/acosh_spec.rb
index 6707de95d3..ccacda37e0 100644
--- a/spec/ruby/core/math/acosh_spec.rb
+++ b/spec/ruby/core/math/acosh_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.acosh" do
it "returns a float" do
- Math.acosh(1.0).should be_kind_of(Float)
+ Math.acosh(1.0).should.is_a?(Float)
end
it "returns the principle value of the inverse hyperbolic cosine of the argument" do
@@ -12,21 +12,21 @@ describe "Math.acosh" do
end
it "raises Math::DomainError if the passed argument is less than -1.0 or greater than 1.0" do
- -> { Math.acosh(1.0 - TOLERANCE) }.should raise_error(Math::DomainError)
- -> { Math.acosh(0) }.should raise_error(Math::DomainError)
- -> { Math.acosh(-1.0) }.should raise_error(Math::DomainError)
+ -> { Math.acosh(1.0 - TOLERANCE) }.should.raise(Math::DomainError)
+ -> { Math.acosh(0) }.should.raise(Math::DomainError)
+ -> { Math.acosh(-1.0) }.should.raise(Math::DomainError)
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.acosh("test") }.should raise_error(TypeError)
+ -> { Math.acosh("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.acosh(nan_value).nan?.should be_true
+ Math.acosh(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.acosh(nil) }.should raise_error(TypeError)
+ -> { Math.acosh(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/asin_spec.rb b/spec/ruby/core/math/asin_spec.rb
index 3a674a1147..1386bccc06 100644
--- a/spec/ruby/core/math/asin_spec.rb
+++ b/spec/ruby/core/math/asin_spec.rb
@@ -4,7 +4,7 @@ require_relative 'fixtures/classes'
# 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)
+ Math.asin(1).should.is_a?(Float)
end
it "returns the arcsine of the argument" do
@@ -17,23 +17,23 @@ describe "Math.asin" do
end
it "raises an Math::DomainError if the argument is greater than 1.0" do
- -> { Math.asin(1.0001) }.should raise_error( Math::DomainError)
+ -> { Math.asin(1.0001) }.should.raise( Math::DomainError)
end
it "raises an Math::DomainError if the argument is less than -1.0" do
- -> { Math.asin(-1.0001) }.should raise_error( Math::DomainError)
+ -> { Math.asin(-1.0001) }.should.raise( Math::DomainError)
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.asin("test") }.should raise_error(TypeError)
+ -> { Math.asin("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.asin(nan_value).nan?.should be_true
+ Math.asin(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.asin(nil) }.should raise_error(TypeError)
+ -> { Math.asin(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/asinh_spec.rb b/spec/ruby/core/math/asinh_spec.rb
index ff8210df0a..8aa019f05f 100644
--- a/spec/ruby/core/math/asinh_spec.rb
+++ b/spec/ruby/core/math/asinh_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.asinh" do
it "returns a float" do
- Math.asinh(1.5).should be_kind_of(Float)
+ Math.asinh(1.5).should.is_a?(Float)
end
it "returns the inverse hyperbolic sin of the argument" do
@@ -19,15 +19,15 @@ describe "Math.asinh" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.asinh("test") }.should raise_error(TypeError)
+ -> { Math.asinh("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.asinh(nan_value).nan?.should be_true
+ Math.asinh(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.asinh(nil) }.should raise_error(TypeError)
+ -> { Math.asinh(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/atan2_spec.rb b/spec/ruby/core/math/atan2_spec.rb
index d4ef369d2a..1f1de506c5 100644
--- a/spec/ruby/core/math/atan2_spec.rb
+++ b/spec/ruby/core/math/atan2_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.atan2" do
it "returns a float" do
- Math.atan2(1.2, 0.5).should be_kind_of(Float)
+ Math.atan2(1.2, 0.5).should.is_a?(Float)
end
it "returns the arc tangent of y, x" do
@@ -14,15 +14,15 @@ describe "Math.atan2" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.atan2(1.0, "test") }.should raise_error(TypeError)
- -> { Math.atan2("test", 0.0) }.should raise_error(TypeError)
- -> { Math.atan2("test", "this") }.should raise_error(TypeError)
+ -> { Math.atan2(1.0, "test") }.should.raise(TypeError)
+ -> { Math.atan2("test", 0.0) }.should.raise(TypeError)
+ -> { Math.atan2("test", "this") }.should.raise(TypeError)
end
it "raises a TypeError if the argument is nil" do
- -> { Math.atan2(nil, 1.0) }.should raise_error(TypeError)
- -> { Math.atan2(-1.0, nil) }.should raise_error(TypeError)
- -> { Math.atan2(nil, nil) }.should raise_error(TypeError)
+ -> { Math.atan2(nil, 1.0) }.should.raise(TypeError)
+ -> { Math.atan2(-1.0, nil) }.should.raise(TypeError)
+ -> { Math.atan2(nil, nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/atan_spec.rb b/spec/ruby/core/math/atan_spec.rb
index 15edf68c05..07d04cdf82 100644
--- a/spec/ruby/core/math/atan_spec.rb
+++ b/spec/ruby/core/math/atan_spec.rb
@@ -4,7 +4,7 @@ require_relative 'fixtures/classes'
# arctangent : (-Inf, Inf) --> (-PI/2, PI/2)
describe "Math.atan" do
it "returns a float" do
- Math.atan(1).should be_kind_of(Float)
+ Math.atan(1).should.is_a?(Float)
end
it "returns the arctangent of the argument" do
@@ -17,15 +17,15 @@ describe "Math.atan" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.atan("test") }.should raise_error(TypeError)
+ -> { Math.atan("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.atan(nan_value).nan?.should be_true
+ Math.atan(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.atan(nil) }.should raise_error(TypeError)
+ -> { Math.atan(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/cbrt_spec.rb b/spec/ruby/core/math/cbrt_spec.rb
index 01cf923c71..4e2383043b 100644
--- a/spec/ruby/core/math/cbrt_spec.rb
+++ b/spec/ruby/core/math/cbrt_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.cbrt" do
it "returns a float" do
- Math.cbrt(1).should be_an_instance_of(Float)
+ Math.cbrt(1).should.instance_of?(Float)
end
it "returns the cubic root of the argument" do
@@ -14,11 +14,11 @@ describe "Math.cbrt" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.cbrt("foobar") }.should raise_error(TypeError)
+ -> { Math.cbrt("foobar") }.should.raise(TypeError)
end
it "raises a TypeError if the argument is nil" do
- -> { Math.cbrt(nil) }.should raise_error(TypeError)
+ -> { Math.cbrt(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/cos_spec.rb b/spec/ruby/core/math/cos_spec.rb
index 006afeb2cc..e8602cde3c 100644
--- a/spec/ruby/core/math/cos_spec.rb
+++ b/spec/ruby/core/math/cos_spec.rb
@@ -4,7 +4,7 @@ require_relative 'fixtures/classes'
# 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)
+ Math.cos(Math::PI).should.is_a?(Float)
end
it "returns the cosine of the argument expressed in radians" do
@@ -16,11 +16,11 @@ describe "Math.cos" do
end
it "raises a TypeError unless the argument is Numeric and has #to_f" do
- -> { Math.cos("test") }.should raise_error(TypeError)
+ -> { Math.cos("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.cos(nan_value).nan?.should be_true
+ Math.cos(nan_value).nan?.should == true
end
describe "coerces its argument with #to_f" do
@@ -31,14 +31,14 @@ describe "Math.cos" do
end
it "raises a TypeError if the given argument can't be converted to a Float" do
- -> { Math.cos(nil) }.should raise_error(TypeError)
- -> { Math.cos(:abc) }.should raise_error(TypeError)
+ -> { Math.cos(nil) }.should.raise(TypeError)
+ -> { Math.cos(:abc) }.should.raise(TypeError)
end
it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to a Float" do
object = mock_numeric('mock-float')
object.should_receive(:to_f).and_raise(NoMethodError)
- -> { Math.cos(object) }.should raise_error(NoMethodError)
+ -> { Math.cos(object) }.should.raise(NoMethodError)
end
end
end
diff --git a/spec/ruby/core/math/cosh_spec.rb b/spec/ruby/core/math/cosh_spec.rb
index 049e117e56..2093d8a74a 100644
--- a/spec/ruby/core/math/cosh_spec.rb
+++ b/spec/ruby/core/math/cosh_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.cosh" do
it "returns a float" do
- Math.cosh(1.0).should be_kind_of(Float)
+ Math.cosh(1.0).should.is_a?(Float)
end
it "returns the hyperbolic cosine of the argument" do
@@ -14,15 +14,15 @@ describe "Math.cosh" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.cosh("test") }.should raise_error(TypeError)
+ -> { Math.cosh("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.cosh(nan_value).nan?.should be_true
+ Math.cosh(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.cosh(nil) }.should raise_error(TypeError)
+ -> { Math.cosh(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/erf_spec.rb b/spec/ruby/core/math/erf_spec.rb
index b4e6248e43..5384e73ae9 100644
--- a/spec/ruby/core/math/erf_spec.rb
+++ b/spec/ruby/core/math/erf_spec.rb
@@ -5,7 +5,7 @@ require_relative 'fixtures/classes'
# 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)
+ Math.erf(1).should.is_a?(Float)
end
it "returns the error function of the argument" do
@@ -21,15 +21,15 @@ describe "Math.erf" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.erf("test") }.should raise_error(TypeError)
+ -> { Math.erf("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.erf(nan_value).nan?.should be_true
+ Math.erf(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.erf(nil) }.should raise_error(TypeError)
+ -> { Math.erf(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/erfc_spec.rb b/spec/ruby/core/math/erfc_spec.rb
index e465f5cf58..4e09a68d1e 100644
--- a/spec/ruby/core/math/erfc_spec.rb
+++ b/spec/ruby/core/math/erfc_spec.rb
@@ -4,7 +4,7 @@ require_relative 'fixtures/classes'
# erfc is the complementary error function
describe "Math.erfc" do
it "returns a float" do
- Math.erf(1).should be_kind_of(Float)
+ Math.erf(1).should.is_a?(Float)
end
it "returns the complementary error function of the argument" do
@@ -20,15 +20,15 @@ describe "Math.erfc" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.erfc("test") }.should raise_error(TypeError)
+ -> { Math.erfc("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.erfc(nan_value).nan?.should be_true
+ Math.erfc(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.erfc(nil) }.should raise_error(TypeError)
+ -> { Math.erfc(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/exp_spec.rb b/spec/ruby/core/math/exp_spec.rb
index 36eb49a8c7..3688482457 100644
--- a/spec/ruby/core/math/exp_spec.rb
+++ b/spec/ruby/core/math/exp_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.exp" do
it "returns a float" do
- Math.exp(1.0).should be_kind_of(Float)
+ Math.exp(1.0).should.is_a?(Float)
end
it "returns the base-e exponential of the argument" do
@@ -14,15 +14,15 @@ describe "Math.exp" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.exp("test") }.should raise_error(TypeError)
+ -> { Math.exp("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.exp(nan_value).nan?.should be_true
+ Math.exp(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.exp(nil) }.should raise_error(TypeError)
+ -> { Math.exp(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/expm1_spec.rb b/spec/ruby/core/math/expm1_spec.rb
new file mode 100644
index 0000000000..35f62b5dbd
--- /dev/null
+++ b/spec/ruby/core/math/expm1_spec.rb
@@ -0,0 +1,37 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+ruby_version_is "4.0" do
+ describe "Math.expm1" do
+ it "calculates Math.exp(arg) - 1" do
+ Math.expm1(3).should == Math.exp(3) - 1
+ end
+
+ it "preserves precision that can be lost otherwise" do
+ Math.expm1(1.0e-16).should be_close(1.0e-16, TOLERANCE)
+ Math.expm1(1.0e-16).should != 0.0
+ end
+
+ it "raises a TypeError if the argument cannot be coerced with Float()" do
+ -> { Math.expm1("test") }.should.raise(TypeError, "can't convert String into Float")
+ end
+
+ it "returns NaN given NaN" do
+ Math.expm1(nan_value).nan?.should == true
+ end
+
+ it "raises a TypeError if the argument is nil" do
+ -> { Math.expm1(nil) }.should.raise(TypeError, "can't convert nil into Float")
+ end
+
+ it "accepts any argument that can be coerced with Float()" do
+ Math.expm1(MathSpecs::Float.new).should be_close(Math::E - 1, TOLERANCE)
+ end
+ end
+
+ describe "Math#expm1" do
+ it "is accessible as a private instance method" do
+ IncludesMath.new.send(:expm1, 23.1415).should be_close(11226018483.0012, TOLERANCE)
+ end
+ end
+end
diff --git a/spec/ruby/core/math/frexp_spec.rb b/spec/ruby/core/math/frexp_spec.rb
index 7dfb493d20..6853e4672f 100644
--- a/spec/ruby/core/math/frexp_spec.rb
+++ b/spec/ruby/core/math/frexp_spec.rb
@@ -9,16 +9,16 @@ describe "Math.frexp" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.frexp("test") }.should raise_error(TypeError)
+ -> { Math.frexp("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
frac, _exp = Math.frexp(nan_value)
- frac.nan?.should be_true
+ frac.nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.frexp(nil) }.should raise_error(TypeError)
+ -> { Math.frexp(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/gamma_spec.rb b/spec/ruby/core/math/gamma_spec.rb
index 386162a087..9a0b14448a 100644
--- a/spec/ruby/core/math/gamma_spec.rb
+++ b/spec/ruby/core/math/gamma_spec.rb
@@ -51,7 +51,7 @@ describe "Math.gamma" do
end
it "raises Math::DomainError given -1" do
- -> { Math.gamma(-1) }.should raise_error(Math::DomainError)
+ -> { Math.gamma(-1) }.should.raise(Math::DomainError)
end
# See https://bugs.ruby-lang.org/issues/10642
@@ -60,10 +60,10 @@ describe "Math.gamma" do
end
it "raises Math::DomainError given negative infinity" do
- -> { Math.gamma(-Float::INFINITY) }.should raise_error(Math::DomainError)
+ -> { Math.gamma(-Float::INFINITY) }.should.raise(Math::DomainError)
end
it "returns NaN given NaN" do
- Math.gamma(nan_value).nan?.should be_true
+ Math.gamma(nan_value).nan?.should == true
end
end
diff --git a/spec/ruby/core/math/hypot_spec.rb b/spec/ruby/core/math/hypot_spec.rb
index 3e0ce74597..4ab5bd4e88 100644
--- a/spec/ruby/core/math/hypot_spec.rb
+++ b/spec/ruby/core/math/hypot_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.hypot" do
it "returns a float" do
- Math.hypot(3, 4).should be_kind_of(Float)
+ Math.hypot(3, 4).should.is_a?(Float)
end
it "returns the length of the hypotenuse of a right triangle with legs given by the arguments" do
@@ -16,17 +16,17 @@ describe "Math.hypot" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.hypot("test", "this") }.should raise_error(TypeError)
+ -> { Math.hypot("test", "this") }.should.raise(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
+ Math.hypot(nan_value, 0).nan?.should == true
+ Math.hypot(0, nan_value).nan?.should == true
+ Math.hypot(nan_value, nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.hypot(nil, nil) }.should raise_error(TypeError)
+ -> { Math.hypot(nil, nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/ldexp_spec.rb b/spec/ruby/core/math/ldexp_spec.rb
index 6dcf94a663..1864b7455a 100644
--- a/spec/ruby/core/math/ldexp_spec.rb
+++ b/spec/ruby/core/math/ldexp_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.ldexp" do
it "returns a float" do
- Math.ldexp(1.0, 2).should be_kind_of(Float)
+ Math.ldexp(1.0, 2).should.is_a?(Float)
end
it "returns the argument multiplied by 2**n" do
@@ -15,27 +15,27 @@ describe "Math.ldexp" do
end
it "raises a TypeError if the first argument cannot be coerced with Float()" do
- -> { Math.ldexp("test", 2) }.should raise_error(TypeError)
+ -> { Math.ldexp("test", 2) }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.ldexp(nan_value, 0).nan?.should be_true
+ Math.ldexp(nan_value, 0).nan?.should == true
end
it "raises RangeError if NaN is given as the second arg" do
- -> { Math.ldexp(0, nan_value) }.should raise_error(RangeError)
+ -> { Math.ldexp(0, nan_value) }.should.raise(RangeError)
end
it "raises a TypeError if the second argument cannot be coerced with Integer()" do
- -> { Math.ldexp(3.2, "this") }.should raise_error(TypeError)
+ -> { Math.ldexp(3.2, "this") }.should.raise(TypeError)
end
it "raises a TypeError if the first argument is nil" do
- -> { Math.ldexp(nil, 2) }.should raise_error(TypeError)
+ -> { Math.ldexp(nil, 2) }.should.raise(TypeError)
end
it "raises a TypeError if the second argument is nil" do
- -> { Math.ldexp(3.1, nil) }.should raise_error(TypeError)
+ -> { Math.ldexp(3.1, nil) }.should.raise(TypeError)
end
it "accepts any first argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/lgamma_spec.rb b/spec/ruby/core/math/lgamma_spec.rb
index 33e7836448..38f07d0bf8 100644
--- a/spec/ruby/core/math/lgamma_spec.rb
+++ b/spec/ruby/core/math/lgamma_spec.rb
@@ -5,10 +5,8 @@ describe "Math.lgamma" 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
+ it "returns [Infinity, ...] when passed -1" do
+ Math.lgamma(-1)[0].should == infinity_value
end
it "returns [Infinity, -1] when passed -0.0" do
@@ -40,15 +38,14 @@ describe "Math.lgamma" do
end
it "raises Math::DomainError when passed -Infinity" do
- -> { Math.lgamma(-infinity_value) }.should raise_error(Math::DomainError)
+ -> { Math.lgamma(-infinity_value) }.should.raise(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
+ it "returns [NaN, ...] when passed NaN" do
+ Math.lgamma(nan_value)[0].should.nan?
end
end
diff --git a/spec/ruby/core/math/log10_spec.rb b/spec/ruby/core/math/log10_spec.rb
index c4daedcd5c..7576a67002 100644
--- a/spec/ruby/core/math/log10_spec.rb
+++ b/spec/ruby/core/math/log10_spec.rb
@@ -4,7 +4,7 @@ require_relative 'fixtures/classes'
# The common logarithm, having base 10
describe "Math.log10" do
it "returns a float" do
- Math.log10(1).should be_kind_of(Float)
+ Math.log10(1).should.is_a?(Float)
end
it "returns the base-10 logarithm of the argument" do
@@ -16,19 +16,23 @@ describe "Math.log10" do
end
it "raises an Math::DomainError if the argument is less than 0" do
- -> { Math.log10(-1e-15) }.should raise_error(Math::DomainError)
+ -> { Math.log10(-1e-15) }.should.raise(Math::DomainError)
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.log10("test") }.should raise_error(TypeError)
+ -> { Math.log10("test") }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError if passed a numerical argument as a string" do
+ -> { Math.log10("1.0") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.log10(nan_value).nan?.should be_true
+ Math.log10(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.log10(nil) }.should raise_error(TypeError)
+ -> { Math.log10(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/log1p_spec.rb b/spec/ruby/core/math/log1p_spec.rb
new file mode 100644
index 0000000000..181b462ded
--- /dev/null
+++ b/spec/ruby/core/math/log1p_spec.rb
@@ -0,0 +1,49 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+ruby_version_is "4.0" do
+ describe "Math.log1p" do
+ it "calculates Math.log(1 + arg)" do
+ Math.log1p(3).should == Math.log(1 + 3)
+ end
+
+ it "preserves precision that can be lost otherwise" do
+ Math.log1p(1e-16).should be_close(1.0e-16, TOLERANCE)
+ Math.log1p(1e-16).should != 0.0
+ end
+
+ it "raises an Math::DomainError if the argument is less than 1" do
+ -> { Math.log1p(-1-1e-15) }.should.raise(Math::DomainError, "Numerical argument is out of domain - log1p")
+ end
+
+ it "raises a TypeError if the argument cannot be coerced with Float()" do
+ -> { Math.log1p("test") }.should.raise(TypeError, "can't convert String into Float")
+ end
+
+ it "raises a TypeError for numerical values passed as string" do
+ -> { Math.log1p("10") }.should.raise(TypeError, "can't convert String into Float")
+ end
+
+ it "does not accept a second argument for the base" do
+ -> { Math.log1p(9, 3) }.should.raise(ArgumentError, "wrong number of arguments (given 2, expected 1)")
+ end
+
+ it "returns NaN given NaN" do
+ Math.log1p(nan_value).nan?.should == true
+ end
+
+ it "raises a TypeError if the argument is nil" do
+ -> { Math.log1p(nil) }.should.raise(TypeError, "can't convert nil into Float")
+ end
+
+ it "accepts any argument that can be coerced with Float()" do
+ Math.log1p(MathSpecs::Float.new).should be_close(0.6931471805599453, TOLERANCE)
+ end
+ end
+
+ describe "Math#log1p" do
+ it "is accessible as a private instance method" do
+ IncludesMath.new.send(:log1p, 4.21).should be_close(1.65057985576528, TOLERANCE)
+ end
+ end
+end
diff --git a/spec/ruby/core/math/log2_spec.rb b/spec/ruby/core/math/log2_spec.rb
index 3d4d41d130..e38a8bb67f 100644
--- a/spec/ruby/core/math/log2_spec.rb
+++ b/spec/ruby/core/math/log2_spec.rb
@@ -16,23 +16,23 @@ describe "Math.log2" do
end
it "raises Math::DomainError if the argument is less than 0" do
- -> { Math.log2(-1e-15) }.should raise_error( Math::DomainError)
+ -> { Math.log2(-1e-15) }.should.raise( Math::DomainError)
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.log2("test") }.should raise_error(TypeError)
+ -> { Math.log2("test") }.should.raise(TypeError)
end
it "raises a TypeError if passed a numerical argument as a string" do
- -> { Math.log2("1.0") }.should raise_error(TypeError)
+ -> { Math.log2("1.0") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.log2(nan_value).nan?.should be_true
+ Math.log2(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.log2(nil) }.should raise_error(TypeError)
+ -> { Math.log2(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/log_spec.rb b/spec/ruby/core/math/log_spec.rb
index 6c5036ba81..7e0bc13bc6 100644
--- a/spec/ruby/core/math/log_spec.rb
+++ b/spec/ruby/core/math/log_spec.rb
@@ -4,7 +4,7 @@ require_relative 'fixtures/classes'
# The natural logarithm, having base Math::E
describe "Math.log" do
it "returns a float" do
- Math.log(1).should be_kind_of(Float)
+ Math.log(1).should.is_a?(Float)
end
it "returns the natural logarithm of the argument" do
@@ -16,15 +16,15 @@ describe "Math.log" do
end
it "raises an Math::DomainError if the argument is less than 0" do
- -> { Math.log(-1e-15) }.should raise_error(Math::DomainError)
+ -> { Math.log(-1e-15) }.should.raise(Math::DomainError)
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.log("test") }.should raise_error(TypeError)
+ -> { Math.log("test") }.should.raise(TypeError)
end
it "raises a TypeError for numerical values passed as string" do
- -> { Math.log("10") }.should raise_error(TypeError)
+ -> { Math.log("10") }.should.raise(TypeError)
end
it "accepts a second argument for the base" do
@@ -33,16 +33,16 @@ describe "Math.log" do
end
it "raises a TypeError when the numerical base cannot be coerced to a float" do
- -> { Math.log(10, "2") }.should raise_error(TypeError)
- -> { Math.log(10, nil) }.should raise_error(TypeError)
+ -> { Math.log(10, "2") }.should.raise(TypeError)
+ -> { Math.log(10, nil) }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.log(nan_value).nan?.should be_true
+ Math.log(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.log(nil) }.should raise_error(TypeError)
+ -> { Math.log(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/shared/atanh.rb b/spec/ruby/core/math/shared/atanh.rb
index 3fb64153a0..48a6bf836e 100644
--- a/spec/ruby/core/math/shared/atanh.rb
+++ b/spec/ruby/core/math/shared/atanh.rb
@@ -1,6 +1,6 @@
describe :math_atanh_base, shared: true do
it "returns a float" do
- @object.send(@method, 0.5).should be_an_instance_of(Float)
+ @object.send(@method, 0.5).should.instance_of?(Float)
end
it "returns the inverse hyperbolic tangent of the argument" do
@@ -11,11 +11,11 @@ describe :math_atanh_base, shared: true do
end
it "raises a TypeError if the argument is nil" do
- -> { @object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @object.send(@method, nil) }.should.raise(TypeError)
end
it "raises a TypeError if the argument is not a Numeric" do
- -> { @object.send(@method, "test") }.should raise_error(TypeError)
+ -> { @object.send(@method, "test") }.should.raise(TypeError)
end
it "returns Infinity if x == 1.0" do
@@ -29,16 +29,16 @@ end
describe :math_atanh_private, shared: true do
it "is a private instance method" do
- Math.should have_private_instance_method(@method)
+ Math.private_instance_methods(false).should.include?(@method)
end
end
describe :math_atanh_no_complex, shared: true do
it "raises a Math::DomainError for arguments greater than 1.0" do
- -> { @object.send(@method, 1.0 + Float::EPSILON) }.should raise_error(Math::DomainError)
+ -> { @object.send(@method, 1.0 + Float::EPSILON) }.should.raise(Math::DomainError)
end
it "raises a Math::DomainError for arguments less than -1.0" do
- -> { @object.send(@method, -1.0 - Float::EPSILON) }.should raise_error(Math::DomainError)
+ -> { @object.send(@method, -1.0 - Float::EPSILON) }.should.raise(Math::DomainError)
end
end
diff --git a/spec/ruby/core/math/sin_spec.rb b/spec/ruby/core/math/sin_spec.rb
index 8e944bc95f..a9479e3aec 100644
--- a/spec/ruby/core/math/sin_spec.rb
+++ b/spec/ruby/core/math/sin_spec.rb
@@ -4,7 +4,7 @@ require_relative 'fixtures/classes'
# 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)
+ Math.sin(Math::PI).should.is_a?(Float)
end
it "returns the sine of the argument expressed in radians" do
@@ -16,15 +16,15 @@ describe "Math.sin" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.sin("test") }.should raise_error(TypeError)
+ -> { Math.sin("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.sin(nan_value).nan?.should be_true
+ Math.sin(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.sin(nil) }.should raise_error(TypeError)
+ -> { Math.sin(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/sinh_spec.rb b/spec/ruby/core/math/sinh_spec.rb
index 027c2395a7..de0f06affa 100644
--- a/spec/ruby/core/math/sinh_spec.rb
+++ b/spec/ruby/core/math/sinh_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.sinh" do
it "returns a float" do
- Math.sinh(1.2).should be_kind_of(Float)
+ Math.sinh(1.2).should.is_a?(Float)
end
it "returns the hyperbolic sin of the argument" do
@@ -14,15 +14,15 @@ describe "Math.sinh" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.sinh("test") }.should raise_error(TypeError)
+ -> { Math.sinh("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.sinh(nan_value).nan?.should be_true
+ Math.sinh(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.sinh(nil) }.should raise_error(TypeError)
+ -> { Math.sinh(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/sqrt_spec.rb b/spec/ruby/core/math/sqrt_spec.rb
index 918e7c3a17..545fa4d1c2 100644
--- a/spec/ruby/core/math/sqrt_spec.rb
+++ b/spec/ruby/core/math/sqrt_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.sqrt" do
it "returns a float" do
- Math.sqrt(1).should be_kind_of(Float)
+ Math.sqrt(1).should.is_a?(Float)
end
it "returns the square root of the argument" do
@@ -13,15 +13,15 @@ describe "Math.sqrt" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.sqrt("test") }.should raise_error(TypeError)
+ -> { Math.sqrt("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.sqrt(nan_value).nan?.should be_true
+ Math.sqrt(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.sqrt(nil) }.should raise_error(TypeError)
+ -> { Math.sqrt(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
@@ -29,7 +29,7 @@ describe "Math.sqrt" do
end
it "raises a Math::DomainError when given a negative number" do
- -> { Math.sqrt(-1) }.should raise_error(Math::DomainError)
+ -> { Math.sqrt(-1) }.should.raise(Math::DomainError)
end
end
diff --git a/spec/ruby/core/math/tan_spec.rb b/spec/ruby/core/math/tan_spec.rb
index 67307f1e6e..c3e773f318 100644
--- a/spec/ruby/core/math/tan_spec.rb
+++ b/spec/ruby/core/math/tan_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.tan" do
it "returns a float" do
- Math.tan(1.35).should be_kind_of(Float)
+ Math.tan(1.35).should.is_a?(Float)
end
it "returns the tangent of the argument" do
@@ -19,15 +19,15 @@ describe "Math.tan" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.tan("test") }.should raise_error(TypeError)
+ -> { Math.tan("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.tan(nan_value).nan?.should be_true
+ Math.tan(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.tan(nil) }.should raise_error(TypeError)
+ -> { Math.tan(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/tanh_spec.rb b/spec/ruby/core/math/tanh_spec.rb
index 568f8dfa77..74a938ffd8 100644
--- a/spec/ruby/core/math/tanh_spec.rb
+++ b/spec/ruby/core/math/tanh_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "Math.tanh" do
it "returns a float" do
- Math.tanh(0.5).should be_kind_of(Float)
+ Math.tanh(0.5).should.is_a?(Float)
end
it "returns the hyperbolic tangent of the argument" do
@@ -16,15 +16,15 @@ describe "Math.tanh" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- -> { Math.tanh("test") }.should raise_error(TypeError)
+ -> { Math.tanh("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.tanh(nan_value).nan?.should be_true
+ Math.tanh(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- -> { Math.tanh(nil) }.should raise_error(TypeError)
+ -> { Math.tanh(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do