mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@a6b8805
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6530b14cee
commit
8c5b60eb22
218 changed files with 4069 additions and 328 deletions
|
|
@ -1,10 +1,12 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/to_i', __FILE__)
|
||||
require File.expand_path('../shared/integer_rounding', __FILE__)
|
||||
|
||||
describe "Integer#round" do
|
||||
it_behaves_like(:integer_to_i, :round)
|
||||
it_behaves_like(:integer_rounding_positive_precision, :round)
|
||||
|
||||
ruby_version_is ""..."2.5" do
|
||||
ruby_version_is ""..."2.5" do # Not just since 2.4
|
||||
it "rounds itself as a float if passed a positive precision" do
|
||||
[2, -4, 10**70, -10**100].each do |v|
|
||||
v.round(42).should eql(v.to_f)
|
||||
|
|
@ -12,20 +14,6 @@ describe "Integer#round" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.5" do
|
||||
it "returns itself if passed a positive precision" do
|
||||
[2, -4, 10**70, -10**100].each do |v|
|
||||
v.round(42).should eql(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "returns itself if passed zero" do
|
||||
[2, -4, 10**70, -10**100].each do |v|
|
||||
v.round(0).should eql(v)
|
||||
end
|
||||
end
|
||||
|
||||
# redmine:5228
|
||||
it "returns itself rounded if passed a negative value" do
|
||||
+249.round(-2).should eql(+200)
|
||||
|
|
@ -74,4 +62,34 @@ describe "Integer#round" do
|
|||
obj.stub!(:to_int).and_return([])
|
||||
lambda { 42.round(obj) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
ruby_version_is "2.4" do
|
||||
it "returns different rounded values depending on the half option" do
|
||||
25.round(-1, half: :up).should eql(30)
|
||||
25.round(-1, half: :down).should eql(20)
|
||||
25.round(-1, half: :even).should eql(20)
|
||||
35.round(-1, half: :up).should eql(40)
|
||||
35.round(-1, half: :down).should eql(30)
|
||||
35.round(-1, half: :even).should eql(40)
|
||||
(-25).round(-1, half: :up).should eql(-30)
|
||||
(-25).round(-1, half: :down).should eql(-20)
|
||||
(-25).round(-1, half: :even).should eql(-20)
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.4"..."2.5" do
|
||||
it "returns itself as a float if passed a positive precision and the half option" do
|
||||
35.round(1, half: :up).should eql(35.0)
|
||||
35.round(1, half: :down).should eql(35.0)
|
||||
35.round(1, half: :even).should eql(35.0)
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.5" do
|
||||
it "returns itself if passed a positive precision and the half option" do
|
||||
35.round(1, half: :up).should eql(35)
|
||||
35.round(1, half: :down).should eql(35)
|
||||
35.round(1, half: :even).should eql(35)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue