diff options
Diffstat (limited to 'spec/ruby/core/float/shared')
| -rw-r--r-- | spec/ruby/core/float/shared/abs.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/core/float/shared/arg.rb | 36 | ||||
| -rw-r--r-- | spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb | 32 | ||||
| -rw-r--r-- | spec/ruby/core/float/shared/comparison_exception_in_coerce.rb | 34 | ||||
| -rw-r--r-- | spec/ruby/core/float/shared/equal.rb | 17 | ||||
| -rw-r--r-- | spec/ruby/core/float/shared/modulo.rb | 48 | ||||
| -rw-r--r-- | spec/ruby/core/float/shared/quo.rb | 59 | ||||
| -rw-r--r-- | spec/ruby/core/float/shared/to_i.rb | 16 |
8 files changed, 21 insertions, 223 deletions
diff --git a/spec/ruby/core/float/shared/abs.rb b/spec/ruby/core/float/shared/abs.rb index 607983322d..ab21480e24 100644 --- a/spec/ruby/core/float/shared/abs.rb +++ b/spec/ruby/core/float/shared/abs.rb @@ -16,6 +16,6 @@ describe :float_abs, shared: true do end it "returns NaN if NaN" do - nan_value.send(@method).nan?.should be_true + nan_value.send(@method).nan?.should == true end end diff --git a/spec/ruby/core/float/shared/arg.rb b/spec/ruby/core/float/shared/arg.rb deleted file mode 100644 index 136cf19ec8..0000000000 --- a/spec/ruby/core/float/shared/arg.rb +++ /dev/null @@ -1,36 +0,0 @@ -describe :float_arg, shared: true do - it "returns NaN if NaN" do - f = nan_value - f.send(@method).nan?.should be_true - end - - it "returns self if NaN" do - f = nan_value - f.send(@method).should equal(f) - end - - it "returns 0 if positive" do - 1.0.send(@method).should == 0 - end - - it "returns 0 if +0.0" do - 0.0.send(@method).should == 0 - end - - it "returns 0 if +Infinity" do - infinity_value.send(@method).should == 0 - end - - it "returns Pi if negative" do - (-1.0).send(@method).should == Math::PI - end - - # This was established in r23960 - it "returns Pi if -0.0" do - (-0.0).send(@method).should == Math::PI - end - - it "returns Pi if -Infinity" do - (-infinity_value).send(@method).should == Math::PI - end -end diff --git a/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb b/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb index 19a02572d8..bd3bf9019f 100644 --- a/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb +++ b/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb @@ -1,33 +1,11 @@ require_relative '../fixtures/classes' describe :float_arithmetic_exception_in_coerce, shared: true do - ruby_version_is ""..."2.5" do - it "rescues exception (StandardError and subclasses) raised in other#coerce and raises TypeError" do - b = mock("numeric with failed #coerce") - b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) + it "does not rescue exception raised in other#coerce" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) - # e.g. 1.0 > b - -> { 1.0.send(@method, b) }.should raise_error(TypeError, /MockObject can't be coerced into Float/) - end - - it "does not rescue Exception and StandardError siblings raised in other#coerce" do - [Exception, NoMemoryError].each do |exception| - b = mock("numeric with failed #coerce") - b.should_receive(:coerce).and_raise(exception) - - # e.g. 1.0 > b - -> { 1.0.send(@method, b) }.should raise_error(exception) - end - end - end - - ruby_version_is "2.5" do - it "does not rescue exception raised in other#coerce" do - b = mock("numeric with failed #coerce") - b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) - - # e.g. 1.0 > b - -> { 1.0.send(@method, b) }.should raise_error(FloatSpecs::CoerceError) - end + # e.g. 1.0 > b + -> { 1.0.send(@method, b) }.should.raise(FloatSpecs::CoerceError) end end diff --git a/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb b/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb index f8ded53644..eec5d8daf9 100644 --- a/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb +++ b/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb @@ -1,35 +1,11 @@ require_relative '../fixtures/classes' describe :float_comparison_exception_in_coerce, shared: true do - ruby_version_is ""..."2.5" do - it "rescues exception (StandardError and subclasses) raised in other#coerce and raises ArgumentError" do - b = mock("numeric with failed #coerce") - b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) + it "does not rescue exception raised in other#coerce" do + b = mock("numeric with failed #coerce") + b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) - # e.g. 1.0 > b - -> { - -> { 1.0.send(@method, b) }.should raise_error(ArgumentError, /comparison of Float with MockObject failed/) - }.should complain(/Numerical comparison operators will no more rescue exceptions of #coerce/) - end - - it "does not rescue Exception and StandardError siblings raised in other#coerce" do - [Exception, NoMemoryError].each do |exception| - b = mock("numeric with failed #coerce") - b.should_receive(:coerce).and_raise(exception) - - # e.g. 1.0 > b - -> { 1.0.send(@method, b) }.should raise_error(exception) - end - end - end - - ruby_version_is "2.5" do - it "does not rescue exception raised in other#coerce" do - b = mock("numeric with failed #coerce") - b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) - - # e.g. 1.0 > b - -> { 1.0.send(@method, b) }.should raise_error(FloatSpecs::CoerceError) - end + # e.g. 1.0 > b + -> { 1.0.send(@method, b) }.should.raise(FloatSpecs::CoerceError) end end diff --git a/spec/ruby/core/float/shared/equal.rb b/spec/ruby/core/float/shared/equal.rb deleted file mode 100644 index 668aa069b5..0000000000 --- a/spec/ruby/core/float/shared/equal.rb +++ /dev/null @@ -1,17 +0,0 @@ -describe :float_equal, shared: true do - it "returns true if self has the same value as other" do - 1.0.send(@method, 1).should == true - 2.71828.send(@method, 1.428).should == false - -4.2.send(@method, 4.2).should == false - end - - it "calls 'other == self' if coercion fails" do - x = mock('other') - def x.==(other) - 2.0 == other - end - - 1.0.send(@method, x).should == false - 2.0.send(@method, x).should == true - end -end diff --git a/spec/ruby/core/float/shared/modulo.rb b/spec/ruby/core/float/shared/modulo.rb deleted file mode 100644 index 6700bd4f4e..0000000000 --- a/spec/ruby/core/float/shared/modulo.rb +++ /dev/null @@ -1,48 +0,0 @@ -describe :float_modulo, shared: true do - it "returns self modulo other" do - 6543.21.send(@method, 137).should be_close(104.21, TOLERANCE) - 5667.19.send(@method, bignum_value).should be_close(5667.19, TOLERANCE) - 6543.21.send(@method, 137.24).should be_close(92.9299999999996, TOLERANCE) - - -1.0.send(@method, 1).should == 0 - end - - it "returns self when modulus is +Infinity" do - 4.2.send(@method, Float::INFINITY).should == 4.2 - end - - it "returns -Infinity when modulus is -Infinity" do - 4.2.send(@method, -Float::INFINITY).should == -Float::INFINITY - end - - it "returns NaN when called on NaN or Infinities" do - Float::NAN.send(@method, 42).should be_nan - Float::INFINITY.send(@method, 42).should be_nan - (-Float::INFINITY).send(@method, 42).should be_nan - end - - it "returns NaN when modulus is NaN" do - 4.2.send(@method, Float::NAN).should be_nan - end - - it "returns -0.0 when called on -0.0 with a non zero modulus" do - r = (-0.0).send(@method, 42) - r.should == 0 - (1/r).should < 0 - - r = (-0.0).send(@method, Float::INFINITY) - r.should == 0 - (1/r).should < 0 - end - - it "tries to coerce the modulus" do - obj = mock("modulus") - obj.should_receive(:coerce).with(1.25).and_return([1.25, 0.5]) - (1.25 % obj).should == 0.25 - end - - it "raises a ZeroDivisionError if other is zero" do - -> { 1.0.send(@method, 0) }.should raise_error(ZeroDivisionError) - -> { 1.0.send(@method, 0.0) }.should raise_error(ZeroDivisionError) - end -end diff --git a/spec/ruby/core/float/shared/quo.rb b/spec/ruby/core/float/shared/quo.rb deleted file mode 100644 index 3487824f70..0000000000 --- a/spec/ruby/core/float/shared/quo.rb +++ /dev/null @@ -1,59 +0,0 @@ -describe :float_quo, shared: true do - it "performs floating-point division between self and a Fixnum" do - 8.9.send(@method, 7).should == 1.2714285714285716 - end - - it "performs floating-point division between self and a Bignum" do - 8.9.send(@method, 9999999999999**9).should == 8.900000000008011e-117 - end - - it "performs floating-point division between self and a Float" do - 2827.22.send(@method, 872.111111).should == 3.2418116961704433 - end - - it "returns NaN when the argument is NaN" do - -1819.999999.send(@method, nan_value).nan?.should be_true - 11109.1981271.send(@method, nan_value).nan?.should be_true - end - - it "returns Infinity when the argument is 0.0" do - 2827.22.send(@method, 0.0).infinite?.should == 1 - end - - it "returns -Infinity when the argument is 0.0 and self is negative" do - -48229.282.send(@method, 0.0).infinite?.should == -1 - end - - it "returns Infinity when the argument is 0" do - 2827.22.send(@method, 0).infinite?.should == 1 - end - - it "returns -Infinity when the argument is 0 and self is negative" do - -48229.282.send(@method, 0).infinite?.should == -1 - end - - it "returns 0.0 when the argument is Infinity" do - 47292.2821.send(@method, infinity_value).should == 0.0 - end - - it "returns -0.0 when the argument is -Infinity" do - 1.9999918.send(@method, -infinity_value).should == -0.0 - end - - it "performs floating-point division between self and a Rational" do - 74620.09.send(@method, Rational(2,3)).should == 111930.135 - end - - it "performs floating-point division between self and a Complex" do - 74620.09.send(@method, Complex(8,2)).should == Complex( - 8778.834117647059, -2194.7085294117646) - end - - it "raises a TypeError when argument isn't numeric" do - -> { 27292.2.send(@method, mock('non-numeric')) }.should raise_error(TypeError) - end - - it "raises an ArgumentError when passed multiple arguments" do - -> { 272.221.send(@method, 6,0.2) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/core/float/shared/to_i.rb b/spec/ruby/core/float/shared/to_i.rb index 960295f095..1e6f941467 100644 --- a/spec/ruby/core/float/shared/to_i.rb +++ b/spec/ruby/core/float/shared/to_i.rb @@ -1,10 +1,14 @@ describe :float_to_i, shared: true do it "returns self truncated to an Integer" do - 899.2.send(@method).should eql(899) - -1.122256e-45.send(@method).should eql(0) - 5_213_451.9201.send(@method).should eql(5213451) - 1.233450999123389e+12.send(@method).should eql(1233450999123) - -9223372036854775808.1.send(@method).should eql(-9223372036854775808) - 9223372036854775808.1.send(@method).should eql(9223372036854775808) + 899.2.send(@method).should.eql?(899) + -1.122256e-45.send(@method).should.eql?(0) + 5_213_451.9201.send(@method).should.eql?(5213451) + 1.233450999123389e+12.send(@method).should.eql?(1233450999123) + -9223372036854775808.1.send(@method).should.eql?(-9223372036854775808) + 9223372036854775808.1.send(@method).should.eql?(9223372036854775808) + end + + it "raises a FloatDomainError for NaN" do + -> { nan_value.send(@method) }.should.raise(FloatDomainError) end end |
