diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-04-27 18:53:23 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-04-27 18:53:23 +0200 |
commit | a1b4816759418ca8fe510e8739622fc5d77ab0f0 (patch) | |
tree | 9d4fb6091d0086817f5bde46bf1150e9130d34fd /spec/ruby/core/float/round_spec.rb | |
parent | 00c33d9c232ed1a79eda17acd7231ac93caa162b (diff) |
Update to ruby/spec@15c9619
Diffstat (limited to 'spec/ruby/core/float/round_spec.rb')
-rw-r--r-- | spec/ruby/core/float/round_spec.rb | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/spec/ruby/core/float/round_spec.rb b/spec/ruby/core/float/round_spec.rb index a21173e139..d5ca532c5a 100644 --- a/spec/ruby/core/float/round_spec.rb +++ b/spec/ruby/core/float/round_spec.rb @@ -83,17 +83,35 @@ describe "Float#round" do -2.4e200.round(-200).should eql( -2 * 10 ** 200 ) end - ruby_version_is "2.4" do - it "returns different rounded values depending on the half option" do - 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: :up).should eql(4) - 3.5.round(half: :down).should eql(3) - 3.5.round(half: :even).should eql(4) - (-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 "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) + 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) + end + + it "raises FloatDomainError for exceptional values with a half option" do + lambda { (+infinity_value).round(half: :up) }.should raise_error(FloatDomainError) + lambda { (-infinity_value).round(half: :down) }.should raise_error(FloatDomainError) + lambda { nan_value.round(half: :even) }.should raise_error(FloatDomainError) + end + + it "raise for a non-existent round mode" do + lambda { 14.2.round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense") end end |