diff options
Diffstat (limited to 'spec/ruby/core/float')
| -rw-r--r-- | spec/ruby/core/float/ceil_spec.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/float/floor_spec.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/float/round_spec.rb | 69 |
3 files changed, 43 insertions, 34 deletions
diff --git a/spec/ruby/core/float/ceil_spec.rb b/spec/ruby/core/float/ceil_spec.rb index 75f5610292..5236a133f5 100644 --- a/spec/ruby/core/float/ceil_spec.rb +++ b/spec/ruby/core/float/ceil_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' require_relative '../integer/shared/integer_ceil_precision' describe "Float#ceil" do - context "with precision" do + context "with values equal to integers" do it_behaves_like :integer_ceil_precision, :Float end @@ -20,7 +20,9 @@ describe "Float#ceil" do 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/floor_spec.rb b/spec/ruby/core/float/floor_spec.rb index 8b492ef473..1fafdadee9 100644 --- a/spec/ruby/core/float/floor_spec.rb +++ b/spec/ruby/core/float/floor_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' require_relative '../integer/shared/integer_floor_precision' describe "Float#floor" do - context "with precision" do + context "with values equal to integers" do it_behaves_like :integer_floor_precision, :Float end @@ -20,7 +20,9 @@ describe "Float#floor" do 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/round_spec.rb b/spec/ruby/core/float/round_spec.rb index 7e8c792051..3e6575100b 100644 --- a/spec/ruby/core/float/round_spec.rb +++ b/spec/ruby/core/float/round_spec.rb @@ -66,6 +66,7 @@ describe "Float#round" do it "works for corner cases" do 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 @@ -145,37 +146,35 @@ describe "Float#round" do -4.809999999999999.round(5, half: :even).should eql(-4.81) end - ruby_bug "#19318", ""..."3.3" do - # 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 + # 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 @@ -197,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 |
