diff options
Diffstat (limited to 'spec/ruby/core/float')
37 files changed, 434 insertions, 181 deletions
diff --git a/spec/ruby/core/float/ceil_spec.rb b/spec/ruby/core/float/ceil_spec.rb index 7fc18d304c..efd1e6feb2 100644 --- a/spec/ruby/core/float/ceil_spec.rb +++ b/spec/ruby/core/float/ceil_spec.rb @@ -1,21 +1,28 @@ require_relative '../../spec_helper' +require_relative '../integer/shared/integer_ceil_precision' describe "Float#ceil" do + context "with values equal to integers" do + it_behaves_like :integer_ceil_precision, :Float + end + it "returns the smallest Integer greater than or equal to self" do - -1.2.ceil.should eql( -1) - -1.0.ceil.should eql( -1) - 0.0.ceil.should eql( 0 ) - 1.3.ceil.should eql( 2 ) - 3.0.ceil.should eql( 3 ) - -9223372036854775808.1.ceil.should eql(-9223372036854775808) - +9223372036854775808.1.ceil.should eql(+9223372036854775808) + -1.2.ceil.should.eql?( -1) + -1.0.ceil.should.eql?( -1) + 0.0.ceil.should.eql?( 0 ) + 1.3.ceil.should.eql?( 2 ) + 3.0.ceil.should.eql?( 3 ) + -9223372036854775808.1.ceil.should.eql?(-9223372036854775808) + +9223372036854775808.1.ceil.should.eql?(+9223372036854775808) end it "returns the smallest number greater than or equal to self with an optionally given precision" do - 2.1679.ceil(0).should eql(3) - 214.94.ceil(-1).should eql(220) - 7.0.ceil(1).should eql(7.0) - -1.234.ceil(2).should eql(-1.23) - 5.123812.ceil(4).should eql(5.1239) + 2.1679.ceil(0).should.eql?(3) + 214.94.ceil(-1).should.eql?(220) + 7.0.ceil(1).should.eql?(7.0) + 200.0.ceil(-2).should.eql?(200) + -1.234.ceil(2).should.eql?(-1.23) + 5.123812.ceil(4).should.eql?(5.1239) + 10.00001.ceil(5).should.eql?(10.00001) end end diff --git a/spec/ruby/core/float/coerce_spec.rb b/spec/ruby/core/float/coerce_spec.rb index ea108f3303..baa831dcf6 100644 --- a/spec/ruby/core/float/coerce_spec.rb +++ b/spec/ruby/core/float/coerce_spec.rb @@ -9,10 +9,10 @@ describe "Float#coerce" do 1.0.coerce(3.14).should == [3.14, 1.0] a, b = -0.0.coerce(bignum_value) - a.should be_close(9223372036854775808.0, TOLERANCE) + a.should be_close(18446744073709551616.0, TOLERANCE) b.should be_close(-0.0, TOLERANCE) a, b = 1.0.coerce(bignum_value) - a.should be_close(9223372036854775808.0, TOLERANCE) + a.should be_close(18446744073709551616.0, TOLERANCE) b.should be_close(1.0, TOLERANCE) end end diff --git a/spec/ruby/core/float/comparison_spec.rb b/spec/ruby/core/float/comparison_spec.rb index 51bb5a52db..e9adf2fd6a 100644 --- a/spec/ruby/core/float/comparison_spec.rb +++ b/spec/ruby/core/float/comparison_spec.rb @@ -7,13 +7,32 @@ describe "Float#<=>" do ((bignum_value*1.1) <=> bignum_value).should == 1 end - it "returns nil when either argument is NaN" do - (nan_value <=> 71.2).should be_nil - (1771.176 <=> nan_value).should be_nil + it "returns nil if one side is NaN" do + [1.0, 42, bignum_value].each { |n| + (nan_value <=> n).should == nil + (n <=> nan_value).should == nil + } + end + + it "handles positive infinity" do + [1.0, 42, bignum_value].each { |n| + (infinity_value <=> n).should == 1 + (n <=> infinity_value).should == -1 + } + end + + it "handles negative infinity" do + [1.0, 42, bignum_value].each { |n| + (-infinity_value <=> n).should == -1 + (n <=> -infinity_value).should == 1 + } end it "returns nil when the given argument is not a Float" do - (1.0 <=> "1").should be_nil + (1.0 <=> "1").should == nil + (1.0 <=> "1".freeze).should == nil + (1.0 <=> :one).should == nil + (1.0 <=> true).should == nil end it "compares using #coerce when argument is not a Float" do @@ -43,24 +62,52 @@ describe "Float#<=>" do bad_coercible = klass.new -> { 4.2 <=> bad_coercible - }.should raise_error(TypeError, "coerce must return [x, y]") + }.should.raise(TypeError, "coerce must return [x, y]") end - # The 4 tests below are taken from matz's revision 23730 for Ruby trunk - # - it "returns 1 when self is Infinity and other is a Bignum" do + it "returns the correct result when one side is infinite" do (infinity_value <=> Float::MAX.to_i*2).should == 1 + (-Float::MAX.to_i*2 <=> infinity_value).should == -1 + (-infinity_value <=> -Float::MAX.to_i*2).should == -1 + (-Float::MAX.to_i*2 <=> -infinity_value).should == 1 end - it "returns -1 when self is negative and other is Infinity" do - (-Float::MAX.to_i*2 <=> infinity_value).should == -1 + it "returns 0 when self is Infinity and other is infinite?=1" do + obj = Object.new + def obj.infinite? + 1 + end + (infinity_value <=> obj).should == 0 end - it "returns -1 when self is -Infinity and other is negative" do - (-infinity_value <=> -Float::MAX.to_i*2).should == -1 + it "returns 1 when self is Infinity and other is infinite?=-1" do + obj = Object.new + def obj.infinite? + -1 + end + (infinity_value <=> obj).should == 1 end - it "returns 1 when self is negative and other is -Infinity" do - (-Float::MAX.to_i*2 <=> -infinity_value).should == 1 + it "returns 1 when self is Infinity and other is infinite?=nil (which means finite)" do + obj = Object.new + def obj.infinite? + nil + end + (infinity_value <=> obj).should == 1 + end + + it "returns 0 for -0.0 and 0.0" do + (-0.0 <=> 0.0).should == 0 + (0.0 <=> -0.0).should == 0 + end + + it "returns 0 for -0.0 and 0" do + (-0.0 <=> 0).should == 0 + (0 <=> -0.0).should == 0 + end + + it "returns 0 for 0.0 and 0" do + (0.0 <=> 0).should == 0 + (0 <=> 0.0).should == 0 end end diff --git a/spec/ruby/core/float/constants_spec.rb b/spec/ruby/core/float/constants_spec.rb index 497e0ae188..1b71ee8adf 100644 --- a/spec/ruby/core/float/constants_spec.rb +++ b/spec/ruby/core/float/constants_spec.rb @@ -50,6 +50,6 @@ describe "Float constant" do end it "NAN is 'not a number'" do - Float::NAN.nan?.should be_true + Float::NAN.nan?.should == true end end diff --git a/spec/ruby/core/float/denominator_spec.rb b/spec/ruby/core/float/denominator_spec.rb index 6f4fcfcf23..85beaa98cd 100644 --- a/spec/ruby/core/float/denominator_spec.rb +++ b/spec/ruby/core/float/denominator_spec.rb @@ -12,7 +12,7 @@ describe "Float#denominator" do it "returns an Integer" do @numbers.each do |number| - number.denominator.should be_kind_of(Integer) + number.denominator.should.is_a?(Integer) end end diff --git a/spec/ruby/core/float/divide_spec.rb b/spec/ruby/core/float/divide_spec.rb index d8f71a6b98..68a2c550a7 100644 --- a/spec/ruby/core/float/divide_spec.rb +++ b/spec/ruby/core/float/divide_spec.rb @@ -16,24 +16,28 @@ describe "Float#/" do end it "returns +Infinity when dividing non-zero by zero of the same sign" do - (1.0 / 0.0).should be_positive_infinity - (-1.0 / -0.0).should be_positive_infinity + (1.0 / 0.0).should.infinite? == 1 + (-1.0 / -0.0).should.infinite? == 1 end it "returns -Infinity when dividing non-zero by zero of opposite sign" do - (-1.0 / 0.0).should be_negative_infinity - (1.0 / -0.0).should be_negative_infinity + (-1.0 / 0.0).should.infinite? == -1 + (1.0 / -0.0).should.infinite? == -1 end it "returns NaN when dividing zero by zero" do - (0.0 / 0.0).should be_nan - (-0.0 / 0.0).should be_nan - (0.0 / -0.0).should be_nan - (-0.0 / -0.0).should be_nan + (0.0 / 0.0).should.nan? + (-0.0 / 0.0).should.nan? + (0.0 / -0.0).should.nan? + (-0.0 / -0.0).should.nan? end it "raises a TypeError when given a non-Numeric" do - -> { 13.0 / "10" }.should raise_error(TypeError) - -> { 13.0 / :symbol }.should raise_error(TypeError) + -> { 13.0 / "10" }.should.raise(TypeError) + -> { 13.0 / :symbol }.should.raise(TypeError) + end + + it "divides correctly by Rational numbers" do + (1.2345678901234567 / Rational(1, 10000000000000000000)).should == 1.2345678901234567e+19 end end diff --git a/spec/ruby/core/float/divmod_spec.rb b/spec/ruby/core/float/divmod_spec.rb index ec55dd3681..7ed6cd3487 100644 --- a/spec/ruby/core/float/divmod_spec.rb +++ b/spec/ruby/core/float/divmod_spec.rb @@ -3,41 +3,41 @@ require_relative '../../spec_helper' describe "Float#divmod" do it "returns an [quotient, modulus] from dividing self by other" do values = 3.14.divmod(2) - values[0].should eql(1) + values[0].should.eql?(1) values[1].should be_close(1.14, TOLERANCE) values = 2.8284.divmod(3.1415) - values[0].should eql(0) + values[0].should.eql?(0) values[1].should be_close(2.8284, TOLERANCE) values = -1.0.divmod(bignum_value) - values[0].should eql(-1) - values[1].should be_close(9223372036854775808.000, TOLERANCE) + values[0].should.eql?(-1) + values[1].should be_close(18446744073709551616.0, TOLERANCE) values = -1.0.divmod(1) - values[0].should eql(-1) - values[1].should eql(0.0) + values[0].should.eql?(-1) + values[1].should.eql?(0.0) end # Behaviour established as correct in r23953 it "raises a FloatDomainError if self is NaN" do - -> { nan_value.divmod(1) }.should raise_error(FloatDomainError) + -> { nan_value.divmod(1) }.should.raise(FloatDomainError) end # Behaviour established as correct in r23953 it "raises a FloatDomainError if other is NaN" do - -> { 1.divmod(nan_value) }.should raise_error(FloatDomainError) + -> { 1.0.divmod(nan_value) }.should.raise(FloatDomainError) end # Behaviour established as correct in r23953 it "raises a FloatDomainError if self is Infinity" do - -> { infinity_value.divmod(1) }.should raise_error(FloatDomainError) + -> { infinity_value.divmod(1) }.should.raise(FloatDomainError) end it "raises a ZeroDivisionError if other is zero" do - -> { 1.0.divmod(0) }.should raise_error(ZeroDivisionError) - -> { 1.0.divmod(0.0) }.should raise_error(ZeroDivisionError) + -> { 1.0.divmod(0) }.should.raise(ZeroDivisionError) + -> { 1.0.divmod(0.0) }.should.raise(ZeroDivisionError) end # redmine #5276" it "returns the correct [quotient, modulus] even for large quotient" do - 0.59.divmod(7.761021455128987e-11).first.should eql(7602092113) + 0.59.divmod(7.761021455128987e-11).first.should.eql?(7602092113) end end diff --git a/spec/ruby/core/float/dup_spec.rb b/spec/ruby/core/float/dup_spec.rb index 294da8e2bc..b474e21325 100644 --- a/spec/ruby/core/float/dup_spec.rb +++ b/spec/ruby/core/float/dup_spec.rb @@ -3,6 +3,6 @@ require_relative '../../spec_helper' describe "Float#dup" do it "returns self" do float = 2.4 - float.dup.should equal(float) + float.dup.should.equal?(float) end end diff --git a/spec/ruby/core/float/eql_spec.rb b/spec/ruby/core/float/eql_spec.rb index 6b5f91db33..cf1ad8416f 100644 --- a/spec/ruby/core/float/eql_spec.rb +++ b/spec/ruby/core/float/eql_spec.rb @@ -2,15 +2,15 @@ require_relative '../../spec_helper' describe "Float#eql?" do it "returns true if other is a Float equal to self" do - 0.0.eql?(0.0).should be_true + 0.0.eql?(0.0).should == true end it "returns false if other is a Float not equal to self" do - 1.0.eql?(1.1).should be_false + 1.0.eql?(1.1).should == false end it "returns false if other is not a Float" do - 1.0.eql?(1).should be_false - 1.0.eql?(:one).should be_false + 1.0.eql?(1).should == false + 1.0.eql?(:one).should == false end end diff --git a/spec/ruby/core/float/float_spec.rb b/spec/ruby/core/float/float_spec.rb index 263ae82079..46b2eff372 100644 --- a/spec/ruby/core/float/float_spec.rb +++ b/spec/ruby/core/float/float_spec.rb @@ -8,12 +8,12 @@ describe "Float" do it ".allocate raises a TypeError" do -> do Float.allocate - end.should raise_error(TypeError) + end.should.raise(TypeError) end it ".new is undefined" do -> do Float.new - end.should raise_error(NoMethodError) + end.should.raise(NoMethodError) end end diff --git a/spec/ruby/core/float/floor_spec.rb b/spec/ruby/core/float/floor_spec.rb index 046216d36d..f77300eb04 100644 --- a/spec/ruby/core/float/floor_spec.rb +++ b/spec/ruby/core/float/floor_spec.rb @@ -1,21 +1,28 @@ require_relative '../../spec_helper' +require_relative '../integer/shared/integer_floor_precision' describe "Float#floor" do + context "with values equal to integers" do + it_behaves_like :integer_floor_precision, :Float + end + it "returns the largest Integer less than or equal to self" do - -1.2.floor.should eql( -2) - -1.0.floor.should eql( -1) - 0.0.floor.should eql( 0 ) - 1.0.floor.should eql( 1 ) - 5.9.floor.should eql( 5 ) - -9223372036854775808.1.floor.should eql(-9223372036854775808) - +9223372036854775808.1.floor.should eql(+9223372036854775808) + -1.2.floor.should.eql?( -2) + -1.0.floor.should.eql?( -1) + 0.0.floor.should.eql?( 0 ) + 1.0.floor.should.eql?( 1 ) + 5.9.floor.should.eql?( 5 ) + -9223372036854775808.1.floor.should.eql?(-9223372036854775808) + +9223372036854775808.1.floor.should.eql?(+9223372036854775808) end it "returns the largest number less than or equal to self with an optionally given precision" do - 2.1679.floor(0).should eql(2) - 214.94.floor(-1).should eql(210) - 7.0.floor(1).should eql(7.0) - -1.234.floor(2).should eql(-1.24) - 5.123812.floor(4).should eql(5.1238) + 2.1679.floor(0).should.eql?(2) + 214.94.floor(-1).should.eql?(210) + 7.0.floor(1).should.eql?(7.0) + 200.0.floor(-2).should.eql?(200) + -1.234.floor(2).should.eql?(-1.24) + 5.123812.floor(4).should.eql?(5.1238) + 10.00001.floor(5).should.eql?(10.00001) end end diff --git a/spec/ruby/core/float/gt_spec.rb b/spec/ruby/core/float/gt_spec.rb index 0d73f1c3df..5194796b46 100644 --- a/spec/ruby/core/float/gt_spec.rb +++ b/spec/ruby/core/float/gt_spec.rb @@ -11,7 +11,28 @@ describe "Float#>" do end it "raises an ArgumentError when given a non-Numeric" do - -> { 5.0 > "4" }.should raise_error(ArgumentError) - -> { 5.0 > mock('x') }.should raise_error(ArgumentError) + -> { 5.0 > "4" }.should.raise(ArgumentError) + -> { 5.0 > mock('x') }.should.raise(ArgumentError) + end + + it "returns false if one side is NaN" do + [1.0, 42, bignum_value].each { |n| + (nan_value > n).should == false + (n > nan_value).should == false + } + end + + it "handles positive infinity" do + [1.0, 42, bignum_value].each { |n| + (infinity_value > n).should == true + (n > infinity_value).should == false + } + end + + it "handles negative infinity" do + [1.0, 42, bignum_value].each { |n| + (-infinity_value > n).should == false + (n > -infinity_value).should == true + } end end diff --git a/spec/ruby/core/float/gte_spec.rb b/spec/ruby/core/float/gte_spec.rb index 98ec60b70b..4a62725d53 100644 --- a/spec/ruby/core/float/gte_spec.rb +++ b/spec/ruby/core/float/gte_spec.rb @@ -11,7 +11,28 @@ describe "Float#>=" do end it "raises an ArgumentError when given a non-Numeric" do - -> { 5.0 >= "4" }.should raise_error(ArgumentError) - -> { 5.0 >= mock('x') }.should raise_error(ArgumentError) + -> { 5.0 >= "4" }.should.raise(ArgumentError) + -> { 5.0 >= mock('x') }.should.raise(ArgumentError) + end + + it "returns false if one side is NaN" do + [1.0, 42, bignum_value].each { |n| + (nan_value >= n).should == false + (n >= nan_value).should == false + } + end + + it "handles positive infinity" do + [1.0, 42, bignum_value].each { |n| + (infinity_value >= n).should == true + (n >= infinity_value).should == false + } + end + + it "handles negative infinity" do + [1.0, 42, bignum_value].each { |n| + (-infinity_value >= n).should == false + (n >= -infinity_value).should == true + } end end diff --git a/spec/ruby/core/float/lt_spec.rb b/spec/ruby/core/float/lt_spec.rb index c01b6e0e02..0f0e1752bd 100644 --- a/spec/ruby/core/float/lt_spec.rb +++ b/spec/ruby/core/float/lt_spec.rb @@ -11,7 +11,28 @@ describe "Float#<" do end it "raises an ArgumentError when given a non-Numeric" do - -> { 5.0 < "4" }.should raise_error(ArgumentError) - -> { 5.0 < mock('x') }.should raise_error(ArgumentError) + -> { 5.0 < "4" }.should.raise(ArgumentError) + -> { 5.0 < mock('x') }.should.raise(ArgumentError) + end + + it "returns false if one side is NaN" do + [1.0, 42, bignum_value].each { |n| + (nan_value < n).should == false + (n < nan_value).should == false + } + end + + it "handles positive infinity" do + [1.0, 42, bignum_value].each { |n| + (infinity_value < n).should == false + (n < infinity_value).should == true + } + end + + it "handles negative infinity" do + [1.0, 42, bignum_value].each { |n| + (-infinity_value < n).should == true + (n < -infinity_value).should == false + } end end diff --git a/spec/ruby/core/float/lte_spec.rb b/spec/ruby/core/float/lte_spec.rb index 66f2ddc2c7..afb64ade09 100644 --- a/spec/ruby/core/float/lte_spec.rb +++ b/spec/ruby/core/float/lte_spec.rb @@ -12,7 +12,28 @@ describe "Float#<=" do end it "raises an ArgumentError when given a non-Numeric" do - -> { 5.0 <= "4" }.should raise_error(ArgumentError) - -> { 5.0 <= mock('x') }.should raise_error(ArgumentError) + -> { 5.0 <= "4" }.should.raise(ArgumentError) + -> { 5.0 <= mock('x') }.should.raise(ArgumentError) + end + + it "returns false if one side is NaN" do + [1.0, 42, bignum_value].each { |n| + (nan_value <= n).should == false + (n <= nan_value).should == false + } + end + + it "handles positive infinity" do + [1.0, 42, bignum_value].each { |n| + (infinity_value <= n).should == false + (n <= infinity_value).should == true + } + end + + it "handles negative infinity" do + [1.0, 42, bignum_value].each { |n| + (-infinity_value <= n).should == true + (n <= -infinity_value).should == false + } end end diff --git a/spec/ruby/core/float/magnitude_spec.rb b/spec/ruby/core/float/magnitude_spec.rb index db577c15c5..7cdd8ef28a 100644 --- a/spec/ruby/core/float/magnitude_spec.rb +++ b/spec/ruby/core/float/magnitude_spec.rb @@ -1,3 +1,4 @@ +require_relative "../../spec_helper" require_relative 'shared/abs' describe "Float#magnitude" do diff --git a/spec/ruby/core/float/minus_spec.rb b/spec/ruby/core/float/minus_spec.rb index 5626cbdac2..a4281a397b 100644 --- a/spec/ruby/core/float/minus_spec.rb +++ b/spec/ruby/core/float/minus_spec.rb @@ -6,7 +6,7 @@ describe "Float#-" do it "returns self minus other" do (9_237_212.5280 - 5_280).should be_close(9231932.528, TOLERANCE) - (2_560_496.1691 - bignum_value).should be_close(-9223372036852215808.000, TOLERANCE) + (2_560_496.1691 - bignum_value).should be_close(-18446744073706991616.0, TOLERANCE) (5.5 - 5.5).should be_close(0.0,TOLERANCE) end end diff --git a/spec/ruby/core/float/multiply_spec.rb b/spec/ruby/core/float/multiply_spec.rb index eca0b52c4f..edaaba7e61 100644 --- a/spec/ruby/core/float/multiply_spec.rb +++ b/spec/ruby/core/float/multiply_spec.rb @@ -7,11 +7,11 @@ describe "Float#*" do it "returns self multiplied by other" do (4923.98221 * 2).should be_close(9847.96442, TOLERANCE) (6712.5 * 0.25).should be_close(1678.125, TOLERANCE) - (256.4096 * bignum_value).should be_close(2364961134621118431232.000, TOLERANCE) + (256.4096 * bignum_value).should be_close(4729922269242236862464.0, TOLERANCE) end it "raises a TypeError when given a non-Numeric" do - -> { 13.0 * "10" }.should raise_error(TypeError) - -> { 13.0 * :symbol }.should raise_error(TypeError) + -> { 13.0 * "10" }.should.raise(TypeError) + -> { 13.0 * :symbol }.should.raise(TypeError) end end diff --git a/spec/ruby/core/float/negative_spec.rb b/spec/ruby/core/float/negative_spec.rb index 511d92ade6..484e636adb 100644 --- a/spec/ruby/core/float/negative_spec.rb +++ b/spec/ruby/core/float/negative_spec.rb @@ -3,31 +3,31 @@ require_relative '../../spec_helper' describe "Float#negative?" do describe "on positive numbers" do it "returns false" do - 0.1.negative?.should be_false + 0.1.negative?.should == false end end describe "on zero" do it "returns false" do - 0.0.negative?.should be_false + 0.0.negative?.should == false end end describe "on negative zero" do it "returns false" do - -0.0.negative?.should be_false + -0.0.negative?.should == false end end describe "on negative numbers" do it "returns true" do - -0.1.negative?.should be_true + -0.1.negative?.should == true end end describe "on NaN" do it "returns false" do - nan_value.negative?.should be_false + nan_value.negative?.should == false end end end diff --git a/spec/ruby/core/float/next_float_spec.rb b/spec/ruby/core/float/next_float_spec.rb index 29e2d31146..59892be343 100644 --- a/spec/ruby/core/float/next_float_spec.rb +++ b/spec/ruby/core/float/next_float_spec.rb @@ -9,7 +9,7 @@ describe "Float#next_float" do barely_positive.should < barely_positive.next_float midpoint = barely_positive / 2 - [0.0, barely_positive].should include midpoint + [0.0, barely_positive].should.include? midpoint end it "returns Float::INFINITY for Float::INFINITY" do diff --git a/spec/ruby/core/float/numerator_spec.rb b/spec/ruby/core/float/numerator_spec.rb index 7832e8f056..53b32fdd3d 100644 --- a/spec/ruby/core/float/numerator_spec.rb +++ b/spec/ruby/core/float/numerator_spec.rb @@ -15,7 +15,7 @@ describe "Float#numerator" do it "converts self to a Rational object then returns its numerator" do @numbers.each do |number| - number.infinite?.should be_nil + number.infinite?.should == nil number.numerator.should == Rational(number).numerator end end @@ -25,7 +25,7 @@ describe "Float#numerator" do end it "returns NaN for NaN" do - nan_value.numerator.nan?.should be_true + nan_value.numerator.nan?.should == true end it "returns Infinity for Infinity" do diff --git a/spec/ruby/core/float/plus_spec.rb b/spec/ruby/core/float/plus_spec.rb index 06b136a06b..e3e19d7f39 100644 --- a/spec/ruby/core/float/plus_spec.rb +++ b/spec/ruby/core/float/plus_spec.rb @@ -6,7 +6,7 @@ describe "Float#+" do it "returns self plus other" do (491.213 + 2).should be_close(493.213, TOLERANCE) - (9.99 + bignum_value).should be_close(9223372036854775808.000, TOLERANCE) + (9.99 + bignum_value).should be_close(18446744073709551616.0, TOLERANCE) (1001.99 + 5.219).should be_close(1007.209, TOLERANCE) end end diff --git a/spec/ruby/core/float/positive_spec.rb b/spec/ruby/core/float/positive_spec.rb index 575f92a720..aa87c03151 100644 --- a/spec/ruby/core/float/positive_spec.rb +++ b/spec/ruby/core/float/positive_spec.rb @@ -3,31 +3,31 @@ require_relative '../../spec_helper' describe "Float#positive?" do describe "on positive numbers" do it "returns true" do - 0.1.positive?.should be_true + 0.1.positive?.should == true end end describe "on zero" do it "returns false" do - 0.0.positive?.should be_false + 0.0.positive?.should == false end end describe "on negative zero" do it "returns false" do - -0.0.positive?.should be_false + -0.0.positive?.should == false end end describe "on negative numbers" do it "returns false" do - -0.1.positive?.should be_false + -0.1.positive?.should == false end end describe "on NaN" do it "returns false" do - nan_value.positive?.should be_false + nan_value.positive?.should == false end end end diff --git a/spec/ruby/core/float/prev_float_spec.rb b/spec/ruby/core/float/prev_float_spec.rb index 5e50269da7..2d1f136254 100644 --- a/spec/ruby/core/float/prev_float_spec.rb +++ b/spec/ruby/core/float/prev_float_spec.rb @@ -9,7 +9,7 @@ describe "Float#prev_float" do barely_negative.should > barely_negative.prev_float midpoint = barely_negative / 2 - [0.0, barely_negative].should include midpoint + [0.0, barely_negative].should.include? midpoint end it "returns -Float::INFINITY for -Float::INFINITY" do diff --git a/spec/ruby/core/float/rationalize_spec.rb b/spec/ruby/core/float/rationalize_spec.rb index 0c5bef7ac4..fa8fb5c841 100644 --- a/spec/ruby/core/float/rationalize_spec.rb +++ b/spec/ruby/core/float/rationalize_spec.rb @@ -29,15 +29,15 @@ describe "Float#rationalize" do end it "raises a FloatDomainError for Infinity" do - -> {infinity_value.rationalize}.should raise_error(FloatDomainError) + -> {infinity_value.rationalize}.should.raise(FloatDomainError) end it "raises a FloatDomainError for NaN" do - -> { nan_value.rationalize }.should raise_error(FloatDomainError) + -> { nan_value.rationalize }.should.raise(FloatDomainError) end it "raises ArgumentError when passed more than one argument" do - -> { 0.3.rationalize(0.1, 0.1) }.should raise_error(ArgumentError) - -> { 0.3.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) + -> { 0.3.rationalize(0.1, 0.1) }.should.raise(ArgumentError) + -> { 0.3.rationalize(0.1, 0.1, 2) }.should.raise(ArgumentError) end end diff --git a/spec/ruby/core/float/round_spec.rb b/spec/ruby/core/float/round_spec.rb index 4bd2dc460c..63c1d5689c 100644 --- a/spec/ruby/core/float/round_spec.rb +++ b/spec/ruby/core/float/round_spec.rb @@ -16,51 +16,57 @@ describe "Float#round" do end it "raises FloatDomainError for exceptional values" do - -> { (+infinity_value).round }.should raise_error(FloatDomainError) - -> { (-infinity_value).round }.should raise_error(FloatDomainError) - -> { nan_value.round }.should raise_error(FloatDomainError) + -> { (+infinity_value).round }.should.raise(FloatDomainError) + -> { (-infinity_value).round }.should.raise(FloatDomainError) + -> { nan_value.round }.should.raise(FloatDomainError) end it "rounds self to an optionally given precision" do - 5.5.round(0).should eql(6) - 5.7.round(1).should eql(5.7) + 5.5.round(0).should.eql?(6) + 5.7.round(1).should.eql?(5.7) 1.2345678.round(2).should == 1.23 - 123456.78.round(-2).should eql(123500) # rounded up - -123456.78.round(-2).should eql(-123500) + 123456.78.round(-2).should.eql?(123500) # rounded up + -123456.78.round(-2).should.eql?(-123500) 12.345678.round(3.999).should == 12.346 end + it "correctly rounds exact floats with a numerous digits in a fraction part" do + 0.8241000000000004.round(10).should == 0.8241 + 0.8241000000000002.round(10).should == 0.8241 + end + it "returns zero when passed a negative argument with magnitude greater than magnitude of the whole number portion of the Float" do - 0.8346268.round(-1).should eql(0) + 0.8346268.round(-1).should.eql?(0) end it "raises a TypeError when its argument can not be converted to an Integer" do - -> { 1.0.round("4") }.should raise_error(TypeError) - -> { 1.0.round(nil) }.should raise_error(TypeError) + -> { 1.0.round("4") }.should.raise(TypeError) + -> { 1.0.round(nil) }.should.raise(TypeError) end it "raises FloatDomainError for exceptional values when passed a non-positive precision" do - -> { Float::INFINITY.round( 0) }.should raise_error(FloatDomainError) - -> { Float::INFINITY.round(-2) }.should raise_error(FloatDomainError) - -> { (-Float::INFINITY).round( 0) }.should raise_error(FloatDomainError) - -> { (-Float::INFINITY).round(-2) }.should raise_error(FloatDomainError) + -> { Float::INFINITY.round( 0) }.should.raise(FloatDomainError) + -> { Float::INFINITY.round(-2) }.should.raise(FloatDomainError) + -> { (-Float::INFINITY).round( 0) }.should.raise(FloatDomainError) + -> { (-Float::INFINITY).round(-2) }.should.raise(FloatDomainError) end it "raises RangeError for NAN when passed a non-positive precision" do - -> { Float::NAN.round(0) }.should raise_error(RangeError) - -> { Float::NAN.round(-2) }.should raise_error(RangeError) + -> { Float::NAN.round(0) }.should.raise(RangeError) + -> { Float::NAN.round(-2) }.should.raise(RangeError) end it "returns self for exceptional values when passed a non-negative precision" do Float::INFINITY.round(2).should == Float::INFINITY (-Float::INFINITY).round(2).should == -Float::INFINITY - Float::NAN.round(2).should be_nan + Float::NAN.round(2).should.nan? end # redmine:5227 it "works for corner cases" do - 42.0.round(308).should eql(42.0) - 1.0e307.round(2).should eql(1.0e307) + 42.0.round(308).should.eql?(42.0) + 1.0e307.round(2).should.eql?(1.0e307) + 120.0.round(-1).should.eql?(120) end # redmine:5271 @@ -68,51 +74,117 @@ describe "Float#round" do 0.42.round(2.0**30).should == 0.42 end + it "returns rounded values for not so big argument" do + 0.42.round(2.0**23).should == 0.42 + end + it "returns big values rounded to nearest" do - +2.5e20.round(-20).should eql( +3 * 10 ** 20 ) - -2.5e20.round(-20).should eql( -3 * 10 ** 20 ) + +2.5e20.round(-20).should.eql?( +3 * 10 ** 20 ) + -2.5e20.round(-20).should.eql?( -3 * 10 ** 20 ) end # redmine #5272 it "returns rounded values for big values" do - +2.4e20.round(-20).should eql( +2 * 10 ** 20 ) - -2.4e20.round(-20).should eql( -2 * 10 ** 20 ) - +2.5e200.round(-200).should eql( +3 * 10 ** 200 ) - +2.4e200.round(-200).should eql( +2 * 10 ** 200 ) - -2.5e200.round(-200).should eql( -3 * 10 ** 200 ) - -2.4e200.round(-200).should eql( -2 * 10 ** 200 ) + +2.4e20.round(-20).should.eql?( +2 * 10 ** 20 ) + -2.4e20.round(-20).should.eql?( -2 * 10 ** 20 ) + +2.5e200.round(-200).should.eql?( +3 * 10 ** 200 ) + +2.4e200.round(-200).should.eql?( +2 * 10 ** 200 ) + -2.5e200.round(-200).should.eql?( -3 * 10 ** 200 ) + -2.4e200.round(-200).should.eql?( -2 * 10 ** 200 ) end it "returns different rounded values depending on the half option" do - 2.5.round(half: nil).should eql(3) - 2.5.round(half: :up).should eql(3) - 2.5.round(half: :down).should eql(2) - 2.5.round(half: :even).should eql(2) - 3.5.round(half: nil).should eql(4) - 3.5.round(half: :up).should eql(4) - 3.5.round(half: :down).should eql(3) - 3.5.round(half: :even).should eql(4) - (-2.5).round(half: nil).should eql(-3) - (-2.5).round(half: :up).should eql(-3) - (-2.5).round(half: :down).should eql(-2) - (-2.5).round(half: :even).should eql(-2) + 2.5.round(half: nil).should.eql?(3) + 2.5.round(half: :up).should.eql?(3) + 2.5.round(half: :down).should.eql?(2) + 2.5.round(half: :even).should.eql?(2) + 3.5.round(half: nil).should.eql?(4) + 3.5.round(half: :up).should.eql?(4) + 3.5.round(half: :down).should.eql?(3) + 3.5.round(half: :even).should.eql?(4) + (-2.5).round(half: nil).should.eql?(-3) + (-2.5).round(half: :up).should.eql?(-3) + (-2.5).round(half: :down).should.eql?(-2) + (-2.5).round(half: :even).should.eql?(-2) end it "rounds self to an optionally given precision with a half option" do - 5.55.round(1, half: nil).should eql(5.6) - 5.55.round(1, half: :up).should eql(5.6) - 5.55.round(1, half: :down).should eql(5.5) - 5.55.round(1, half: :even).should eql(5.6) + 5.55.round(1, half: nil).should.eql?(5.6) + 5.55.round(1, half: :up).should.eql?(5.6) + 5.55.round(1, half: :down).should.eql?(5.5) + 5.55.round(1, half: :even).should.eql?(5.6) + -5.55.round(1, half: nil).should.eql?(-5.6) + -5.55.round(1, half: :up).should.eql?(-5.6) + -5.55.round(1, half: :down).should.eql?(-5.5) + -5.55.round(1, half: :even).should.eql?(-5.6) + end + + it "preserves cases where neighbouring floating pointer number increase the decimal places" do + 4.8100000000000005.round(5, half: nil).should.eql?(4.81) + 4.8100000000000005.round(5, half: :up).should.eql?(4.81) + 4.8100000000000005.round(5, half: :down).should.eql?(4.81) + 4.8100000000000005.round(5, half: :even).should.eql?(4.81) + -4.8100000000000005.round(5, half: nil).should.eql?(-4.81) + -4.8100000000000005.round(5, half: :up).should.eql?(-4.81) + -4.8100000000000005.round(5, half: :down).should.eql?(-4.81) + -4.8100000000000005.round(5, half: :even).should.eql?(-4.81) + 4.81.round(5, half: nil).should.eql?(4.81) + 4.81.round(5, half: :up).should.eql?(4.81) + 4.81.round(5, half: :down).should.eql?(4.81) + 4.81.round(5, half: :even).should.eql?(4.81) + -4.81.round(5, half: nil).should.eql?(-4.81) + -4.81.round(5, half: :up).should.eql?(-4.81) + -4.81.round(5, half: :down).should.eql?(-4.81) + -4.81.round(5, half: :even).should.eql?(-4.81) + 4.809999999999999.round(5, half: nil).should.eql?(4.81) + 4.809999999999999.round(5, half: :up).should.eql?(4.81) + 4.809999999999999.round(5, half: :down).should.eql?(4.81) + 4.809999999999999.round(5, half: :even).should.eql?(4.81) + -4.809999999999999.round(5, half: nil).should.eql?(-4.81) + -4.809999999999999.round(5, half: :up).should.eql?(-4.81) + -4.809999999999999.round(5, half: :down).should.eql?(-4.81) + -4.809999999999999.round(5, half: :even).should.eql?(-4.81) + end + + # These numbers are neighbouring floating point numbers round a + # precise value. They test that the rounding modes work correctly + # round that value and precision is not lost which might cause + # incorrect results. + it "does not lose precision during the rounding process" do + 767573.1875850001.round(5, half: nil).should.eql?(767573.18759) + 767573.1875850001.round(5, half: :up).should.eql?(767573.18759) + 767573.1875850001.round(5, half: :down).should.eql?(767573.18759) + 767573.1875850001.round(5, half: :even).should.eql?(767573.18759) + -767573.1875850001.round(5, half: nil).should.eql?(-767573.18759) + -767573.1875850001.round(5, half: :up).should.eql?(-767573.18759) + -767573.1875850001.round(5, half: :down).should.eql?(-767573.18759) + -767573.1875850001.round(5, half: :even).should.eql?(-767573.18759) + 767573.187585.round(5, half: nil).should.eql?(767573.18759) + 767573.187585.round(5, half: :up).should.eql?(767573.18759) + 767573.187585.round(5, half: :down).should.eql?(767573.18758) + 767573.187585.round(5, half: :even).should.eql?(767573.18758) + -767573.187585.round(5, half: nil).should.eql?(-767573.18759) + -767573.187585.round(5, half: :up).should.eql?(-767573.18759) + -767573.187585.round(5, half: :down).should.eql?(-767573.18758) + -767573.187585.round(5, half: :even).should.eql?(-767573.18758) + 767573.1875849998.round(5, half: nil).should.eql?(767573.18758) + 767573.1875849998.round(5, half: :up).should.eql?(767573.18758) + 767573.1875849998.round(5, half: :down).should.eql?(767573.18758) + 767573.1875849998.round(5, half: :even).should.eql?(767573.18758) + -767573.1875849998.round(5, half: nil).should.eql?(-767573.18758) + -767573.1875849998.round(5, half: :up).should.eql?(-767573.18758) + -767573.1875849998.round(5, half: :down).should.eql?(-767573.18758) + -767573.1875849998.round(5, half: :even).should.eql?(-767573.18758) end it "raises FloatDomainError for exceptional values with a half option" do - -> { (+infinity_value).round(half: :up) }.should raise_error(FloatDomainError) - -> { (-infinity_value).round(half: :down) }.should raise_error(FloatDomainError) - -> { nan_value.round(half: :even) }.should raise_error(FloatDomainError) + -> { (+infinity_value).round(half: :up) }.should.raise(FloatDomainError) + -> { (-infinity_value).round(half: :down) }.should.raise(FloatDomainError) + -> { nan_value.round(half: :even) }.should.raise(FloatDomainError) end it "raise for a non-existent round mode" do - -> { 14.2.round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense") + -> { 14.2.round(half: :nonsense) }.should.raise(ArgumentError, "invalid rounding mode: nonsense") end describe "when 0.0 is given" do @@ -124,7 +196,13 @@ describe "Float#round" do it "returns 0 for 0 or undefined ndigits" do (0.0).round.should == 0 (-0.0).round(0).should == 0 - (0.0).round(half: :up) == 0 + (0.0).round(half: :up).should == 0 + end + + it "returns 0 for negative ndigits" do + (0.0).round(-1).should == 0 + (-0.0).round(-1).should == 0 + (0.0).round(-1, half: :up).should == 0 end end end 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 index 136cf19ec8..de0024313d 100644 --- a/spec/ruby/core/float/shared/arg.rb +++ b/spec/ruby/core/float/shared/arg.rb @@ -1,12 +1,12 @@ describe :float_arg, shared: true do it "returns NaN if NaN" do f = nan_value - f.send(@method).nan?.should be_true + f.send(@method).nan?.should == true end it "returns self if NaN" do f = nan_value - f.send(@method).should equal(f) + f.send(@method).should.equal?(f) end it "returns 0 if positive" do 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 eec92d858f..bd3bf9019f 100644 --- a/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb +++ b/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb @@ -6,6 +6,6 @@ describe :float_arithmetic_exception_in_coerce, shared: true do b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) # e.g. 1.0 > b - -> { 1.0.send(@method, b) }.should raise_error(FloatSpecs::CoerceError) + -> { 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 3e2c1e28dd..eec5d8daf9 100644 --- a/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb +++ b/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb @@ -6,6 +6,6 @@ describe :float_comparison_exception_in_coerce, shared: true do b.should_receive(:coerce).and_raise(FloatSpecs::CoerceError) # e.g. 1.0 > b - -> { 1.0.send(@method, b) }.should raise_error(FloatSpecs::CoerceError) + -> { 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 index 668aa069b5..4d524e1cf2 100644 --- a/spec/ruby/core/float/shared/equal.rb +++ b/spec/ruby/core/float/shared/equal.rb @@ -14,4 +14,25 @@ describe :float_equal, shared: true do 1.0.send(@method, x).should == false 2.0.send(@method, x).should == true end + + it "returns false if one side is NaN" do + [1.0, 42, bignum_value].each { |n| + (nan_value.send(@method, n)).should == false + (n.send(@method, nan_value)).should == false + } + end + + it "handles positive infinity" do + [1.0, 42, bignum_value].each { |n| + (infinity_value.send(@method, n)).should == false + (n.send(@method, infinity_value)).should == false + } + end + + it "handles negative infinity" do + [1.0, 42, bignum_value].each { |n| + ((-infinity_value).send(@method, n)).should == false + (n.send(@method, -infinity_value)).should == false + } + end end diff --git a/spec/ruby/core/float/shared/modulo.rb b/spec/ruby/core/float/shared/modulo.rb index 6700bd4f4e..1efee1476d 100644 --- a/spec/ruby/core/float/shared/modulo.rb +++ b/spec/ruby/core/float/shared/modulo.rb @@ -16,13 +16,13 @@ describe :float_modulo, shared: true do 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 + Float::NAN.send(@method, 42).should.nan? + Float::INFINITY.send(@method, 42).should.nan? + (-Float::INFINITY).send(@method, 42).should.nan? end it "returns NaN when modulus is NaN" do - 4.2.send(@method, Float::NAN).should be_nan + 4.2.send(@method, Float::NAN).should.nan? end it "returns -0.0 when called on -0.0 with a non zero modulus" do @@ -42,7 +42,7 @@ describe :float_modulo, shared: true do 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) + -> { 1.0.send(@method, 0) }.should.raise(ZeroDivisionError) + -> { 1.0.send(@method, 0.0) }.should.raise(ZeroDivisionError) end end diff --git a/spec/ruby/core/float/shared/quo.rb b/spec/ruby/core/float/shared/quo.rb index 3487824f70..930187aaf7 100644 --- a/spec/ruby/core/float/shared/quo.rb +++ b/spec/ruby/core/float/shared/quo.rb @@ -1,9 +1,9 @@ describe :float_quo, shared: true do - it "performs floating-point division between self and a Fixnum" do + it "performs floating-point division between self and an Integer" do 8.9.send(@method, 7).should == 1.2714285714285716 end - it "performs floating-point division between self and a Bignum" do + it "performs floating-point division between self and an Integer" do 8.9.send(@method, 9999999999999**9).should == 8.900000000008011e-117 end @@ -12,8 +12,8 @@ describe :float_quo, shared: true do 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 + -1819.999999.send(@method, nan_value).nan?.should == true + 11109.1981271.send(@method, nan_value).nan?.should == true end it "returns Infinity when the argument is 0.0" do @@ -50,10 +50,10 @@ describe :float_quo, shared: true do end it "raises a TypeError when argument isn't numeric" do - -> { 27292.2.send(@method, mock('non-numeric')) }.should raise_error(TypeError) + -> { 27292.2.send(@method, mock('non-numeric')) }.should.raise(TypeError) end it "raises an ArgumentError when passed multiple arguments" do - -> { 272.221.send(@method, 6,0.2) }.should raise_error(ArgumentError) + -> { 272.221.send(@method, 6,0.2) }.should.raise(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 diff --git a/spec/ruby/core/float/shared/to_s.rb b/spec/ruby/core/float/shared/to_s.rb index 0925efc0f7..81ffdd9e81 100644 --- a/spec/ruby/core/float/shared/to_s.rb +++ b/spec/ruby/core/float/shared/to_s.rb @@ -297,12 +297,12 @@ describe :float_to_s, shared: true do it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do Encoding.default_internal = nil - 1.23.send(@method).encoding.should equal(Encoding::US_ASCII) + 1.23.send(@method).encoding.should.equal?(Encoding::US_ASCII) end it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do Encoding.default_internal = Encoding::IBM437 - 5.47.send(@method).encoding.should equal(Encoding::US_ASCII) + 5.47.send(@method).encoding.should.equal?(Encoding::US_ASCII) end end end diff --git a/spec/ruby/core/float/truncate_spec.rb b/spec/ruby/core/float/truncate_spec.rb index 2c80145f9f..1750e3fdbc 100644 --- a/spec/ruby/core/float/truncate_spec.rb +++ b/spec/ruby/core/float/truncate_spec.rb @@ -5,10 +5,10 @@ describe "Float#truncate" do it_behaves_like :float_to_i, :truncate it "returns self truncated to an optionally given precision" do - 2.1679.truncate(0).should eql(2) - 7.1.truncate(1).should eql(7.1) - 214.94.truncate(-1).should eql(210) - -1.234.truncate(2).should eql(-1.23) - 5.123812.truncate(4).should eql(5.1238) + 2.1679.truncate(0).should.eql?(2) + 7.1.truncate(1).should.eql?(7.1) + 214.94.truncate(-1).should.eql?(210) + -1.234.truncate(2).should.eql?(-1.23) + 5.123812.truncate(4).should.eql?(5.1238) end end diff --git a/spec/ruby/core/float/uplus_spec.rb b/spec/ruby/core/float/uplus_spec.rb index 936123558c..b979b2717a 100644 --- a/spec/ruby/core/float/uplus_spec.rb +++ b/spec/ruby/core/float/uplus_spec.rb @@ -4,6 +4,6 @@ describe "Float#+@" do it "returns the same value with same sign (twos complement)" do 34.56.send(:+@).should == 34.56 -34.56.send(:+@).should == -34.56 - 0.0.send(:+@).should eql(0.0) + 0.0.send(:+@).should.eql?(0.0) end end |
