summaryrefslogtreecommitdiff
path: root/spec/ruby/core/rational
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2026-01-28 22:30:21 +0100
committerBenoit Daloze <eregontp@gmail.com>2026-01-28 23:01:22 +0100
commitdbd2ff7adca9b49e4bfa7bc3ec8b83bd437f8cb7 (patch)
tree5f4f1609d2015fde92c25b175b84078dfcf1c92f /spec/ruby/core/rational
parenta8b877a843643fbdccd1a42efaf94ad27705dd55 (diff)
Update to ruby/spec@83e26c9
Diffstat (limited to 'spec/ruby/core/rational')
-rw-r--r--spec/ruby/core/rational/ceil_spec.rb49
-rw-r--r--spec/ruby/core/rational/exponent_spec.rb16
-rw-r--r--spec/ruby/core/rational/floor_spec.rb50
3 files changed, 61 insertions, 54 deletions
diff --git a/spec/ruby/core/rational/ceil_spec.rb b/spec/ruby/core/rational/ceil_spec.rb
index d5bdadf3b6..0c0327448f 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
diff --git a/spec/ruby/core/rational/exponent_spec.rb b/spec/ruby/core/rational/exponent_spec.rb
index 65fbf2ed1c..1f8a03740c 100644
--- a/spec/ruby/core/rational/exponent_spec.rb
+++ b/spec/ruby/core/rational/exponent_spec.rb
@@ -108,37 +108,37 @@ describe "Rational#**" do
it "raises an ArgumentError when self is > 1" do
-> {
(Rational(2) ** bignum_value)
- }.should raise_error(ArgumentError)
+ }.should raise_error(ArgumentError, "exponent is too large")
-> {
(Rational(fixnum_max) ** bignum_value)
- }.should raise_error(ArgumentError)
+ }.should raise_error(ArgumentError, "exponent is too large")
end
it "raises an ArgumentError when self is > 1 and the exponent is negative" do
-> {
(Rational(2) ** -bignum_value)
- }.should raise_error(ArgumentError)
+ }.should raise_error(ArgumentError, "exponent is too large")
-> {
(Rational(fixnum_max) ** -bignum_value)
- }.should raise_error(ArgumentError)
+ }.should raise_error(ArgumentError, "exponent is too large")
end
it "raises an ArgumentError when self is < -1" do
-> {
(Rational(-2) ** bignum_value)
- }.should raise_error(ArgumentError)
+ }.should raise_error(ArgumentError, "exponent is too large")
-> {
(Rational(fixnum_min) ** bignum_value)
- }.should raise_error(ArgumentError)
+ }.should raise_error(ArgumentError, "exponent is too large")
end
it "raises an ArgumentError when self is < -1 and the exponent is negative" do
-> {
(Rational(-2) ** -bignum_value)
- }.should raise_error(ArgumentError)
+ }.should raise_error(ArgumentError, "exponent is too large")
-> {
(Rational(fixnum_min) ** -bignum_value)
- }.should raise_error(ArgumentError)
+ }.should raise_error(ArgumentError, "exponent is too large")
end
end
diff --git a/spec/ruby/core/rational/floor_spec.rb b/spec/ruby/core/rational/floor_spec.rb
index 8068aaf119..5108e363f7 100644
--- a/spec/ruby/core/rational/floor_spec.rb
+++ b/spec/ruby/core/rational/floor_spec.rb
@@ -1,45 +1,49 @@
require_relative "../../spec_helper"
+require_relative "../integer/shared/integer_floor_precision"
describe "Rational#floor" do
+ context "with values equal to integers" do
+ it_behaves_like :integer_floor_precision, :Rational
+ end
+
before do
@rational = Rational(2200, 7)
end
describe "with no arguments (precision = 0)" do
- it "returns an integer" do
- @rational.floor.should be_kind_of(Integer)
- end
- it "returns the truncated value toward negative infinity" do
- @rational.floor.should == 314
- Rational(1, 2).floor.should == 0
- Rational(-1, 2).floor.should == -1
+ it "returns the Integer value rounded toward negative infinity" do
+ @rational.floor.should eql 314
+
+ Rational(1, 2).floor.should eql 0
+ Rational(-1, 2).floor.should eql(-1)
+ Rational(1, 1).floor.should eql 1
end
end
describe "with a precision < 0" do
- it "returns an integer" do
- @rational.floor(-2).should be_kind_of(Integer)
- @rational.floor(-1).should be_kind_of(Integer)
- end
+ it "moves the rounding point n decimal places left, returning an Integer" do
+ @rational.floor(-3).should eql 0
+ @rational.floor(-2).should eql 300
+ @rational.floor(-1).should eql 310
- it "moves the truncation point n decimal places left" do
- @rational.floor(-3).should == 0
- @rational.floor(-2).should == 300
- @rational.floor(-1).should == 310
+ Rational(100, 2).floor(-1).should eql 50
+ Rational(100, 2).floor(-2).should eql 0
+ Rational(-100, 2).floor(-1).should eql(-50)
+ Rational(-100, 2).floor(-2).should eql(-100)
end
end
describe "with a precision > 0" do
- it "returns a Rational" do
- @rational.floor(1).should be_kind_of(Rational)
- @rational.floor(2).should be_kind_of(Rational)
- end
+ it "moves the rounding point n decimal places right, returning a Rational" do
+ @rational.floor(1).should eql Rational(1571, 5)
+ @rational.floor(2).should eql Rational(7857, 25)
+ @rational.floor(3).should eql Rational(62857, 200)
- it "moves the truncation point n decimal places right" do
- @rational.floor(1).should == Rational(1571, 5)
- @rational.floor(2).should == Rational(7857, 25)
- @rational.floor(3).should == Rational(62857, 200)
+ Rational(100, 2).floor(1).should eql Rational(50, 1)
+ Rational(100, 2).floor(2).should eql Rational(50, 1)
+ Rational(-100, 2).floor(1).should eql Rational(-50, 1)
+ Rational(-100, 2).floor(2).should eql Rational(-50, 1)
end
end
end