diff options
Diffstat (limited to 'spec/ruby/core/rational/ceil_spec.rb')
| -rw-r--r-- | spec/ruby/core/rational/ceil_spec.rb | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/spec/ruby/core/rational/ceil_spec.rb b/spec/ruby/core/rational/ceil_spec.rb index d5bdadf3b6..0464eab101 100644 --- a/spec/ruby/core/rational/ceil_spec.rb +++ b/spec/ruby/core/rational/ceil_spec.rb @@ -1,45 +1,48 @@ require_relative "../../spec_helper" +require_relative "../integer/shared/integer_ceil_precision" describe "Rational#ceil" do + context "with values equal to integers" do + it_behaves_like :integer_ceil_precision, :Rational + end + before do @rational = Rational(2200, 7) end describe "with no arguments (precision = 0)" do - it "returns an Integer" do - @rational.ceil.should be_kind_of(Integer) - end + it "returns the Integer value rounded toward positive infinity" do + @rational.ceil.should.eql? 315 - it "returns the truncated value toward positive infinity" do - @rational.ceil.should == 315 - Rational(1, 2).ceil.should == 1 - Rational(-1, 2).ceil.should == 0 + Rational(1, 2).ceil.should.eql? 1 + Rational(-1, 2).ceil.should.eql? 0 + Rational(1, 1).ceil.should.eql? 1 end end describe "with a precision < 0" do - it "returns an Integer" do - @rational.ceil(-2).should be_kind_of(Integer) - @rational.ceil(-1).should be_kind_of(Integer) - end + it "moves the rounding point n decimal places left, returning an Integer" do + @rational.ceil(-3).should.eql? 1000 + @rational.ceil(-2).should.eql? 400 + @rational.ceil(-1).should.eql? 320 - it "moves the truncation point n decimal places left" do - @rational.ceil(-3).should == 1000 - @rational.ceil(-2).should == 400 - @rational.ceil(-1).should == 320 + Rational(100, 2).ceil(-1).should.eql? 50 + Rational(100, 2).ceil(-2).should.eql? 100 + Rational(-100, 2).ceil(-1).should.eql?(-50) + Rational(-100, 2).ceil(-2).should.eql?(0) end end describe "with precision > 0" do - it "returns a Rational" do - @rational.ceil(1).should be_kind_of(Rational) - @rational.ceil(2).should be_kind_of(Rational) - end + it "moves the rounding point n decimal places right, returning a Rational" do + @rational.ceil(1).should.eql? Rational(3143, 10) + @rational.ceil(2).should.eql? Rational(31429, 100) + @rational.ceil(3).should.eql? Rational(157143, 500) - it "moves the truncation point n decimal places right" do - @rational.ceil(1).should == Rational(3143, 10) - @rational.ceil(2).should == Rational(31429, 100) - @rational.ceil(3).should == Rational(157143, 500) + Rational(100, 2).ceil(1).should.eql? Rational(50, 1) + Rational(100, 2).ceil(2).should.eql? Rational(50, 1) + Rational(-100, 2).ceil(1).should.eql? Rational(-50, 1) + Rational(-100, 2).ceil(2).should.eql? Rational(-50, 1) end end end |
