1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2019-04-27 18:53:23 +02:00
parent 00c33d9c23
commit a1b4816759
193 changed files with 3026 additions and 3387 deletions

View file

@ -72,28 +72,35 @@ describe :rational_round, shared: true do
end
end
ruby_version_is "2.4" do
describe "with half option" do
it "returns an Integer when precision is not passed" do
Rational(10, 4).round(half: :up).should == 3
Rational(10, 4).round(half: :down).should == 2
Rational(10, 4).round(half: :even).should == 2
Rational(-10, 4).round(half: :up).should == -3
Rational(-10, 4).round(half: :down).should == -2
Rational(-10, 4).round(half: :even).should == -2
end
describe "with half option" do
it "returns an Integer when precision is not passed" do
Rational(10, 4).round(half: nil).should == 3
Rational(10, 4).round(half: :up).should == 3
Rational(10, 4).round(half: :down).should == 2
Rational(10, 4).round(half: :even).should == 2
Rational(-10, 4).round(half: nil).should == -3
Rational(-10, 4).round(half: :up).should == -3
Rational(-10, 4).round(half: :down).should == -2
Rational(-10, 4).round(half: :even).should == -2
end
it "returns a Rational when the precision is greater than 0" do
Rational(25, 100).round(1, half: :up).should == Rational(3, 10)
Rational(25, 100).round(1, half: :down).should == Rational(1, 5)
Rational(25, 100).round(1, half: :even).should == Rational(1, 5)
Rational(35, 100).round(1, half: :up).should == Rational(2, 5)
Rational(35, 100).round(1, half: :down).should == Rational(3, 10)
Rational(35, 100).round(1, half: :even).should == Rational(2, 5)
Rational(-25, 100).round(1, half: :up).should == Rational(-3, 10)
Rational(-25, 100).round(1, half: :down).should == Rational(-1, 5)
Rational(-25, 100).round(1, half: :even).should == Rational(-1, 5)
end
it "returns a Rational when the precision is greater than 0" do
Rational(25, 100).round(1, half: nil).should == Rational(3, 10)
Rational(25, 100).round(1, half: :up).should == Rational(3, 10)
Rational(25, 100).round(1, half: :down).should == Rational(1, 5)
Rational(25, 100).round(1, half: :even).should == Rational(1, 5)
Rational(35, 100).round(1, half: nil).should == Rational(2, 5)
Rational(35, 100).round(1, half: :up).should == Rational(2, 5)
Rational(35, 100).round(1, half: :down).should == Rational(3, 10)
Rational(35, 100).round(1, half: :even).should == Rational(2, 5)
Rational(-25, 100).round(1, half: nil).should == Rational(-3, 10)
Rational(-25, 100).round(1, half: :up).should == Rational(-3, 10)
Rational(-25, 100).round(1, half: :down).should == Rational(-1, 5)
Rational(-25, 100).round(1, half: :even).should == Rational(-1, 5)
end
it "raise for a non-existent round mode" do
lambda { Rational(10, 4).round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense")
end
end
end