aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/float
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/float')
-rw-r--r--spec/ruby/core/float/ceil_spec.rb14
-rw-r--r--spec/ruby/core/float/dup_spec.rb10
-rw-r--r--spec/ruby/core/float/floor_spec.rb14
-rw-r--r--spec/ruby/core/float/round_spec.rb42
-rw-r--r--spec/ruby/core/float/truncate_spec.rb14
5 files changed, 52 insertions, 42 deletions
diff --git a/spec/ruby/core/float/ceil_spec.rb b/spec/ruby/core/float/ceil_spec.rb
index 8a4f72c70e..7fc18d304c 100644
--- a/spec/ruby/core/float/ceil_spec.rb
+++ b/spec/ruby/core/float/ceil_spec.rb
@@ -11,13 +11,11 @@ describe "Float#ceil" do
+9223372036854775808.1.ceil.should eql(+9223372036854775808)
end
- ruby_version_is "2.4" do
- 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)
- 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)
end
end
diff --git a/spec/ruby/core/float/dup_spec.rb b/spec/ruby/core/float/dup_spec.rb
index 8df7260652..294da8e2bc 100644
--- a/spec/ruby/core/float/dup_spec.rb
+++ b/spec/ruby/core/float/dup_spec.rb
@@ -1,10 +1,8 @@
require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "Float#dup" do
- it "returns self" do
- float = 2.4
- float.dup.should equal(float)
- end
+describe "Float#dup" do
+ it "returns self" do
+ float = 2.4
+ float.dup.should equal(float)
end
end
diff --git a/spec/ruby/core/float/floor_spec.rb b/spec/ruby/core/float/floor_spec.rb
index f20eccae73..046216d36d 100644
--- a/spec/ruby/core/float/floor_spec.rb
+++ b/spec/ruby/core/float/floor_spec.rb
@@ -11,13 +11,11 @@ describe "Float#floor" do
+9223372036854775808.1.floor.should eql(+9223372036854775808)
end
- ruby_version_is "2.4" do
- 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)
- 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)
end
end
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
diff --git a/spec/ruby/core/float/truncate_spec.rb b/spec/ruby/core/float/truncate_spec.rb
index 5c219da960..2c80145f9f 100644
--- a/spec/ruby/core/float/truncate_spec.rb
+++ b/spec/ruby/core/float/truncate_spec.rb
@@ -4,13 +4,11 @@ require_relative 'shared/to_i'
describe "Float#truncate" do
it_behaves_like :float_to_i, :truncate
- ruby_version_is "2.4" do
- 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)
- end
+ 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)
end
end