mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@15c9619
This commit is contained in:
parent
00c33d9c23
commit
a1b4816759
193 changed files with 3026 additions and 3387 deletions
|
@ -6,16 +6,14 @@ describe "Integer#ceil" do
|
|||
it_behaves_like :integer_to_i, :ceil
|
||||
it_behaves_like :integer_rounding_positive_precision, :ceil
|
||||
|
||||
ruby_version_is "2.4" do
|
||||
context "precision argument specified as part of the ceil method is negative" do
|
||||
it "returns the smallest integer greater than self with at least precision.abs trailing zeros" do
|
||||
18.ceil(-1).should eql(20)
|
||||
18.ceil(-2).should eql(100)
|
||||
18.ceil(-3).should eql(1000)
|
||||
-1832.ceil(-1).should eql(-1830)
|
||||
-1832.ceil(-2).should eql(-1800)
|
||||
-1832.ceil(-3).should eql(-1000)
|
||||
end
|
||||
context "precision argument specified as part of the ceil method is negative" do
|
||||
it "returns the smallest integer greater than self with at least precision.abs trailing zeros" do
|
||||
18.ceil(-1).should eql(20)
|
||||
18.ceil(-2).should eql(100)
|
||||
18.ceil(-3).should eql(1000)
|
||||
-1832.ceil(-1).should eql(-1830)
|
||||
-1832.ceil(-2).should eql(-1800)
|
||||
-1832.ceil(-3).should eql(-1000)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,38 +68,24 @@ describe "Integer#coerce" do
|
|||
lambda { a.coerce(:test) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
ruby_version_is ""..."2.4" do
|
||||
it "raises a TypeError when passed a String" do
|
||||
a = bignum_value
|
||||
lambda { a.coerce("123") }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed a Float" do
|
||||
a = bignum_value
|
||||
lambda { a.coerce(12.3) }.should raise_error(TypeError)
|
||||
end
|
||||
it "coerces both values to Floats and returns [other, self] when passed a Float" do
|
||||
a = bignum_value
|
||||
a.coerce(1.2).should == [1.2, a.to_f]
|
||||
end
|
||||
|
||||
ruby_version_is "2.4" do
|
||||
it "coerces both values to Floats and returns [other, self] when passed a Float" do
|
||||
a = bignum_value
|
||||
a.coerce(1.2).should == [1.2, a.to_f]
|
||||
end
|
||||
it "coerces both values to Floats and returns [other, self] when passed a String" do
|
||||
a = bignum_value
|
||||
a.coerce("123").should == [123.0, a.to_f]
|
||||
end
|
||||
|
||||
it "coerces both values to Floats and returns [other, self] when passed a String" do
|
||||
a = bignum_value
|
||||
a.coerce("123").should == [123.0, a.to_f]
|
||||
end
|
||||
it "calls #to_f to coerce other to a Float" do
|
||||
b = mock("bignum value")
|
||||
b.should_receive(:to_f).and_return(1.2)
|
||||
|
||||
it "calls #to_f to coerce other to a Float" do
|
||||
b = mock("bignum value")
|
||||
b.should_receive(:to_f).and_return(1.2)
|
||||
a = bignum_value
|
||||
ary = a.coerce(b)
|
||||
|
||||
a = bignum_value
|
||||
ary = a.coerce(b)
|
||||
|
||||
ary.should == [1.2, a.to_f]
|
||||
end
|
||||
ary.should == [1.2, a.to_f]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,34 +1,32 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
ruby_version_is "2.4" do
|
||||
describe "Integer#digits" do
|
||||
it "returns an array of place values in base-10 by default" do
|
||||
12345.digits.should == [5,4,3,2,1]
|
||||
end
|
||||
describe "Integer#digits" do
|
||||
it "returns an array of place values in base-10 by default" do
|
||||
12345.digits.should == [5,4,3,2,1]
|
||||
end
|
||||
|
||||
it "returns digits by place value of a given radix" do
|
||||
12345.digits(7).should == [4,6,6,0,5]
|
||||
end
|
||||
it "returns digits by place value of a given radix" do
|
||||
12345.digits(7).should == [4,6,6,0,5]
|
||||
end
|
||||
|
||||
it "converts the radix with #to_int" do
|
||||
12345.digits(mock_int(2)).should == [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1]
|
||||
end
|
||||
it "converts the radix with #to_int" do
|
||||
12345.digits(mock_int(2)).should == [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1]
|
||||
end
|
||||
|
||||
it "returns [0] when called on 0, regardless of base" do
|
||||
0.digits.should == [0]
|
||||
0.digits(7).should == [0]
|
||||
end
|
||||
it "returns [0] when called on 0, regardless of base" do
|
||||
0.digits.should == [0]
|
||||
0.digits(7).should == [0]
|
||||
end
|
||||
|
||||
it "raises ArgumentError when calling with a radix less than 2" do
|
||||
lambda { 12345.digits(1) }.should raise_error(ArgumentError)
|
||||
end
|
||||
it "raises ArgumentError when calling with a radix less than 2" do
|
||||
lambda { 12345.digits(1) }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "raises ArgumentError when calling with a negative radix" do
|
||||
lambda { 12345.digits(-2) }.should raise_error(ArgumentError)
|
||||
end
|
||||
it "raises ArgumentError when calling with a negative radix" do
|
||||
lambda { 12345.digits(-2) }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "raises Math::DomainError when calling digits on a negative number" do
|
||||
lambda { -12345.digits(7) }.should raise_error(Math::DomainError)
|
||||
end
|
||||
it "raises Math::DomainError when calling digits on a negative number" do
|
||||
lambda { -12345.digits(7) }.should raise_error(Math::DomainError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
ruby_version_is '2.4' do
|
||||
describe "Integer#dup" do
|
||||
it "returns self for small integers" do
|
||||
integer = 1_000
|
||||
integer.dup.should equal(integer)
|
||||
end
|
||||
describe "Integer#dup" do
|
||||
it "returns self for small integers" do
|
||||
integer = 1_000
|
||||
integer.dup.should equal(integer)
|
||||
end
|
||||
|
||||
it "returns self for large integers" do
|
||||
integer = 4_611_686_018_427_387_905
|
||||
integer.dup.should equal(integer)
|
||||
end
|
||||
it "returns self for large integers" do
|
||||
integer = 4_611_686_018_427_387_905
|
||||
integer.dup.should equal(integer)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,16 +6,14 @@ describe "Integer#floor" do
|
|||
it_behaves_like :integer_to_i, :floor
|
||||
it_behaves_like :integer_rounding_positive_precision, :floor
|
||||
|
||||
ruby_version_is "2.4" do
|
||||
context "precision argument specified as part of the floor method is negative" do
|
||||
it "returns the largest integer less than self with at least precision.abs trailing zeros" do
|
||||
1832.floor(-1).should eql(1830)
|
||||
1832.floor(-2).should eql(1800)
|
||||
1832.floor(-3).should eql(1000)
|
||||
-1832.floor(-1).should eql(-1840)
|
||||
-1832.floor(-2).should eql(-1900)
|
||||
-1832.floor(-3).should eql(-2000)
|
||||
end
|
||||
context "precision argument specified as part of the floor method is negative" do
|
||||
it "returns the largest integer less than self with at least precision.abs trailing zeros" do
|
||||
1832.floor(-1).should eql(1830)
|
||||
1832.floor(-2).should eql(1800)
|
||||
1832.floor(-3).should eql(1000)
|
||||
-1832.floor(-1).should eql(-1840)
|
||||
-1832.floor(-2).should eql(-1900)
|
||||
-1832.floor(-3).should eql(-2000)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,11 +5,9 @@ describe "Integer" do
|
|||
Integer.include?(Comparable).should == true
|
||||
end
|
||||
|
||||
ruby_version_is "2.4" do
|
||||
it "is the class of both small and large integers" do
|
||||
42.class.should equal(Integer)
|
||||
bignum_value.class.should equal(Integer)
|
||||
end
|
||||
it "is the class of both small and large integers" do
|
||||
42.class.should equal(Integer)
|
||||
bignum_value.class.should equal(Integer)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,13 +16,11 @@ ruby_version_is "2.5" do
|
|||
2.pow(8, 15).should == 1
|
||||
end
|
||||
|
||||
ruby_bug '#13669', '2.5'...'2.5.1' do
|
||||
it "works well with bignums" do
|
||||
2.pow(61, 5843009213693951).should eql 3697379018277258
|
||||
2.pow(62, 5843009213693952).should eql 1551748822859776
|
||||
2.pow(63, 5843009213693953).should eql 3103497645717974
|
||||
2.pow(64, 5843009213693954).should eql 363986077738838
|
||||
end
|
||||
it "works well with bignums" do
|
||||
2.pow(61, 5843009213693951).should eql 3697379018277258
|
||||
2.pow(62, 5843009213693952).should eql 1551748822859776
|
||||
2.pow(63, 5843009213693953).should eql 3103497645717974
|
||||
2.pow(64, 5843009213693954).should eql 363986077738838
|
||||
end
|
||||
|
||||
it "handles sign like #divmod does" do
|
||||
|
|
|
@ -63,18 +63,16 @@ describe "Integer#round" do
|
|||
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
|
||||
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
|
||||
|
||||
ruby_version_is "2.4"..."2.5" do
|
||||
|
|
|
@ -5,11 +5,9 @@ describe :integer_rounding_positive_precision, shared: true do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.4" do
|
||||
it "returns self if passed a precision of zero" do
|
||||
[2, -4, 10**70, -10**100].each do |v|
|
||||
v.send(@method, 0).should eql(v)
|
||||
end
|
||||
it "returns self if passed a precision of zero" do
|
||||
[2, -4, 10**70, -10**100].each do |v|
|
||||
v.send(@method, 0).should eql(v)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,16 +6,14 @@ describe "Integer#truncate" do
|
|||
it_behaves_like :integer_to_i, :truncate
|
||||
it_behaves_like :integer_rounding_positive_precision, :truncate
|
||||
|
||||
ruby_version_is "2.4" do
|
||||
context "precision argument specified as part of the truncate method is negative" do
|
||||
it "returns an integer with at least precision.abs trailing zeros" do
|
||||
1832.truncate(-1).should eql(1830)
|
||||
1832.truncate(-2).should eql(1800)
|
||||
1832.truncate(-3).should eql(1000)
|
||||
-1832.truncate(-1).should eql(-1830)
|
||||
-1832.truncate(-2).should eql(-1800)
|
||||
-1832.truncate(-3).should eql(-1000)
|
||||
end
|
||||
context "precision argument specified as part of the truncate method is negative" do
|
||||
it "returns an integer with at least precision.abs trailing zeros" do
|
||||
1832.truncate(-1).should eql(1830)
|
||||
1832.truncate(-2).should eql(1800)
|
||||
1832.truncate(-3).should eql(1000)
|
||||
-1832.truncate(-1).should eql(-1830)
|
||||
-1832.truncate(-2).should eql(-1800)
|
||||
-1832.truncate(-3).should eql(-1000)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue