Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions shared/rational/round.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,29 @@
Rational(3, 2).round(2_097_171).should == Rational(3, 2)
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

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
end
end
end