aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/integer
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-12-27 17:35:32 +0100
committerBenoit Daloze <eregontp@gmail.com>2020-12-27 17:35:32 +0100
commit727c97da1977544c91b9b3677811da3a44af7d53 (patch)
tree4f027117edad10789db57ff4b83242753a89e39d /spec/ruby/core/integer
parent267bed0cd91711e2a8c79219e97431ba22137b01 (diff)
downloadruby-727c97da1977544c91b9b3677811da3a44af7d53.tar.gz
Update to ruby/spec@4ce9f41
Diffstat (limited to 'spec/ruby/core/integer')
-rw-r--r--spec/ruby/core/integer/coerce_spec.rb10
-rw-r--r--spec/ruby/core/integer/comparison_spec.rb6
-rw-r--r--spec/ruby/core/integer/constants_spec.rb32
-rw-r--r--spec/ruby/core/integer/denominator_spec.rb2
-rw-r--r--spec/ruby/core/integer/element_reference_spec.rb12
-rw-r--r--spec/ruby/core/integer/even_spec.rb4
-rw-r--r--spec/ruby/core/integer/gcd_spec.rb4
-rw-r--r--spec/ruby/core/integer/gcdlcm_spec.rb4
-rw-r--r--spec/ruby/core/integer/lcm_spec.rb4
-rw-r--r--spec/ruby/core/integer/left_shift_spec.rb12
-rw-r--r--spec/ruby/core/integer/right_shift_spec.rb10
-rw-r--r--spec/ruby/core/integer/shared/exponent.rb9
-rw-r--r--spec/ruby/core/integer/shared/next.rb12
-rw-r--r--spec/ruby/core/integer/to_r_spec.rb2
-rw-r--r--spec/ruby/core/integer/uminus_spec.rb2
15 files changed, 61 insertions, 64 deletions
diff --git a/spec/ruby/core/integer/coerce_spec.rb b/spec/ruby/core/integer/coerce_spec.rb
index 4d540bfb87..f1f3256032 100644
--- a/spec/ruby/core/integer/coerce_spec.rb
+++ b/spec/ruby/core/integer/coerce_spec.rb
@@ -4,8 +4,8 @@ require 'bigdecimal'
describe "Integer#coerce" do
context "fixnum" do
- describe "when given an Integer" do
- it "returns an array containing two Integers" do
+ describe "when given a Fixnum" do
+ it "returns an array containing two Fixnums" do
1.coerce(2).should == [2, 1]
1.coerce(2).map { |i| i.class }.should == [Integer, Integer]
end
@@ -42,7 +42,7 @@ describe "Integer#coerce" do
end
context "bignum" do
- it "coerces other to an Integer and returns [other, self] when passed an Integer" do
+ it "coerces other to a Bignum and returns [other, self] when passed a Fixnum" do
a = bignum_value
ary = a.coerce(2)
@@ -51,7 +51,7 @@ describe "Integer#coerce" do
ary.should == [2, a]
end
- it "returns [other, self] when passed an Integer" do
+ it "returns [other, self] when passed a Bignum" do
a = bignum_value
b = bignum_value
ary = a.coerce(b)
@@ -61,7 +61,7 @@ describe "Integer#coerce" do
ary.should == [b, a]
end
- it "raises a TypeError when not passed an Integer" do
+ it "raises a TypeError when not passed a Fixnum or Bignum" do
a = bignum_value
-> { a.coerce(nil) }.should raise_error(TypeError)
diff --git a/spec/ruby/core/integer/comparison_spec.rb b/spec/ruby/core/integer/comparison_spec.rb
index a0d8d24119..408c8e52ce 100644
--- a/spec/ruby/core/integer/comparison_spec.rb
+++ b/spec/ruby/core/integer/comparison_spec.rb
@@ -27,7 +27,7 @@ describe "Integer#<=>" do
end
context "bignum" do
- describe "with an Integer" do
+ describe "with a Fixnum" do
it "returns -1 when other is larger" do
(-bignum_value <=> 2).should == -1
end
@@ -37,7 +37,7 @@ describe "Integer#<=>" do
end
end
- describe "with an Integer" do
+ describe "with a Bignum" do
describe "when other is negative" do
it "returns -1 when self is negative and other is larger" do
(-bignum_value(42) <=> -bignum_value).should == -1
@@ -158,7 +158,7 @@ describe "Integer#<=>" do
end
# The tests below are taken from matz's revision 23730 for Ruby trunk
- it "returns 1 when self is Infinity and other is an Integer" do
+ it "returns 1 when self is Infinity and other is a Bignum" do
(infinity_value <=> Float::MAX.to_i*2).should == 1
end
diff --git a/spec/ruby/core/integer/constants_spec.rb b/spec/ruby/core/integer/constants_spec.rb
index 35601f82b9..3b8b01e330 100644
--- a/spec/ruby/core/integer/constants_spec.rb
+++ b/spec/ruby/core/integer/constants_spec.rb
@@ -1,27 +1,25 @@
require_relative '../../spec_helper'
-ruby_version_is ""..."3.0" do
- describe "Fixnum" do
- it "is unified into Integer" do
- suppress_warning do
- Fixnum.should equal(Integer)
- end
+describe "Fixnum" do
+ it "is unified into Integer" do
+ suppress_warning do
+ Fixnum.should equal(Integer)
end
+ end
- it "is deprecated" do
- -> { Fixnum }.should complain(/constant ::Fixnum is deprecated/)
- end
+ it "is deprecated" do
+ -> { Fixnum }.should complain(/constant ::Fixnum is deprecated/)
end
+end
- describe "Bignum" do
- it "is unified into Integer" do
- suppress_warning do
- Bignum.should equal(Integer)
- end
+describe "Bignum" do
+ it "is unified into Integer" do
+ suppress_warning do
+ Bignum.should equal(Integer)
end
+ end
- it "is deprecated" do
- -> { Bignum }.should complain(/constant ::Bignum is deprecated/)
- end
+ it "is deprecated" do
+ -> { Bignum }.should complain(/constant ::Bignum is deprecated/)
end
end
diff --git a/spec/ruby/core/integer/denominator_spec.rb b/spec/ruby/core/integer/denominator_spec.rb
index d19b8175a3..c1477d0757 100644
--- a/spec/ruby/core/integer/denominator_spec.rb
+++ b/spec/ruby/core/integer/denominator_spec.rb
@@ -7,7 +7,7 @@ describe "Integer#denominator" do
@numbers = [
20, # Integer
-2709, # Negative Integer
- 99999999**99, # Integer
+ 99999999**99, # Bignum
-99999**621, # Negative BigNum
0,
1
diff --git a/spec/ruby/core/integer/element_reference_spec.rb b/spec/ruby/core/integer/element_reference_spec.rb
index 6e65c50254..7197ecdc03 100644
--- a/spec/ruby/core/integer/element_reference_spec.rb
+++ b/spec/ruby/core/integer/element_reference_spec.rb
@@ -68,14 +68,14 @@ describe "Integer#[]" do
-> { 3[obj] }.should raise_error(TypeError)
end
- it "calls #to_int to coerce a String to an Integer and returns 0" do
+ it "calls #to_int to coerce a String to a Bignum and returns 0" do
obj = mock('bignum value')
obj.should_receive(:to_int).and_return(bignum_value)
3[obj].should == 0
end
- it "returns 0 when passed a Float in the range of an Integer" do
+ it "returns 0 when passed a Float in the range of a Bignum" do
3[bignum_value.to_f].should == 0
end
@@ -131,16 +131,10 @@ describe "Integer#[]" do
0b000001[-3, 4].should == 0b1000
end
- it "ignores negative upper boundary" do
- 0b101001101[1..-1].should == 0b10100110
- 0b101001101[1..-2].should == 0b10100110
- 0b101001101[1..-3].should == 0b10100110
- end
-
it "ignores upper boundary smaller than lower boundary" do
0b101001101[4..1].should == 0b10100
0b101001101[4..2].should == 0b10100
- 0b101001101[4..3].should == 0b10100
+ 0b101001101[-4..-5].should == 0b1010011010000
end
it "raises FloatDomainError if any boundary is infinity" do
diff --git a/spec/ruby/core/integer/even_spec.rb b/spec/ruby/core/integer/even_spec.rb
index a93f54c74e..a314cc6b19 100644
--- a/spec/ruby/core/integer/even_spec.rb
+++ b/spec/ruby/core/integer/even_spec.rb
@@ -2,7 +2,7 @@ require_relative '../../spec_helper'
describe "Integer#even?" do
context "fixnum" do
- it "returns true for an Integer when it is an even number" do
+ it "returns true for a Fixnum when it is an even number" do
(-2).even?.should be_true
(-1).even?.should be_false
@@ -11,7 +11,7 @@ describe "Integer#even?" do
2.even?.should be_true
end
- it "returns true for an Integer when it is an even number" do
+ it "returns true for a Bignum when it is an even number" do
bignum_value(0).even?.should be_true
bignum_value(1).even?.should be_false
diff --git a/spec/ruby/core/integer/gcd_spec.rb b/spec/ruby/core/integer/gcd_spec.rb
index 82086d742a..961f1c5c2e 100644
--- a/spec/ruby/core/integer/gcd_spec.rb
+++ b/spec/ruby/core/integer/gcd_spec.rb
@@ -31,13 +31,13 @@ describe "Integer#gcd" do
-100.gcd(-100).should == 100
end
- it "accepts an Integer argument" do
+ it "accepts a Bignum argument" do
bignum = 9999**99
bignum.should be_kind_of(Integer)
99.gcd(bignum).should == 99
end
- it "works if self is an Integer" do
+ it "works if self is a Bignum" do
bignum = 9999**99
bignum.should be_kind_of(Integer)
bignum.gcd(99).should == 99
diff --git a/spec/ruby/core/integer/gcdlcm_spec.rb b/spec/ruby/core/integer/gcdlcm_spec.rb
index 2915750f88..ebf45e55a1 100644
--- a/spec/ruby/core/integer/gcdlcm_spec.rb
+++ b/spec/ruby/core/integer/gcdlcm_spec.rb
@@ -26,13 +26,13 @@ describe "Integer#gcdlcm" do
200.gcdlcm(20)[1].should == 200.lcm(20)
end
- it "accepts an Integer argument" do
+ it "accepts a Bignum argument" do
bignum = 91999**99
bignum.should be_kind_of(Integer)
99.gcdlcm(bignum).should == [99.gcd(bignum), 99.lcm(bignum)]
end
- it "works if self is an Integer" do
+ it "works if self is a Bignum" do
bignum = 9999**89
bignum.should be_kind_of(Integer)
bignum.gcdlcm(99).should == [bignum.gcd(99), bignum.lcm(99)]
diff --git a/spec/ruby/core/integer/lcm_spec.rb b/spec/ruby/core/integer/lcm_spec.rb
index 39976ea474..296a001c8c 100644
--- a/spec/ruby/core/integer/lcm_spec.rb
+++ b/spec/ruby/core/integer/lcm_spec.rb
@@ -31,13 +31,13 @@ describe "Integer#lcm" do
-100.lcm(-100).should == 100
end
- it "accepts an Integer argument" do
+ it "accepts a Bignum argument" do
bignum = 9999**99
bignum.should be_kind_of(Integer)
99.lcm(bignum).should == bignum
end
- it "works if self is an Integer" do
+ it "works if self is a Bignum" do
bignum = 9999**99
bignum.should be_kind_of(Integer)
bignum.lcm(99).should == bignum
diff --git a/spec/ruby/core/integer/left_shift_spec.rb b/spec/ruby/core/integer/left_shift_spec.rb
index d2ffe4bbeb..4efcbef334 100644
--- a/spec/ruby/core/integer/left_shift_spec.rb
+++ b/spec/ruby/core/integer/left_shift_spec.rb
@@ -52,17 +52,17 @@ describe "Integer#<< (with n << m)" do
(-7 << -64).should == -1
end
- it "returns 0 when m < 0 and m is an Integer" do
+ it "returns 0 when m < 0 and m is a Bignum" do
(3 << -bignum_value).should == 0
end
- it "returns an Integer == fixnum_max * 2 when fixnum_max << 1 and n > 0" do
+ it "returns an Bignum == fixnum_max * 2 when fixnum_max << 1 and n > 0" do
result = fixnum_max << 1
result.should be_an_instance_of(Integer)
result.should == fixnum_max * 2
end
- it "returns an Integer == fixnum_min * 2 when fixnum_min << 1 and n < 0" do
+ it "returns an Bignum == fixnum_min * 2 when fixnum_min << 1 and n < 0" do
result = fixnum_min << 1
result.should be_an_instance_of(Integer)
result.should == fixnum_min * 2
@@ -127,17 +127,17 @@ describe "Integer#<< (with n << m)" do
(@bignum << -68).should == 0
end
- it "returns 0 when m < 0 and m is an Integer" do
+ it "returns 0 when m < 0 and m is a Bignum" do
(@bignum << -bignum_value).should == 0
end
- it "returns an Integer == fixnum_max when (fixnum_max * 2) << -1 and n > 0" do
+ it "returns a Fixnum == fixnum_max when (fixnum_max * 2) << -1 and n > 0" do
result = (fixnum_max * 2) << -1
result.should be_an_instance_of(Integer)
result.should == fixnum_max
end
- it "returns an Integer == fixnum_min when (fixnum_min * 2) << -1 and n < 0" do
+ it "returns a Fixnum == fixnum_min when (fixnum_min * 2) << -1 and n < 0" do
result = (fixnum_min * 2) << -1
result.should be_an_instance_of(Integer)
result.should == fixnum_min
diff --git a/spec/ruby/core/integer/right_shift_spec.rb b/spec/ruby/core/integer/right_shift_spec.rb
index 62cbe862b9..6abcd8d714 100644
--- a/spec/ruby/core/integer/right_shift_spec.rb
+++ b/spec/ruby/core/integer/right_shift_spec.rb
@@ -56,13 +56,13 @@ describe "Integer#>> (with n >> m)" do
(3 >> bignum_value).should == 0
end
- it "returns an Integer == fixnum_max * 2 when fixnum_max >> -1 and n > 0" do
+ it "returns an Bignum == fixnum_max * 2 when fixnum_max >> -1 and n > 0" do
result = fixnum_max >> -1
result.should be_an_instance_of(Integer)
result.should == fixnum_max * 2
end
- it "returns an Integer == fixnum_min * 2 when fixnum_min >> -1 and n < 0" do
+ it "returns an Bignum == fixnum_min * 2 when fixnum_min >> -1 and n < 0" do
result = fixnum_min >> -1
result.should be_an_instance_of(Integer)
result.should == fixnum_min * 2
@@ -153,17 +153,17 @@ describe "Integer#>> (with n >> m)" do
(@bignum >> 68).should == 0
end
- it "returns 0 when m is an Integer" do
+ it "returns 0 when m is a Bignum" do
(@bignum >> bignum_value).should == 0
end
- it "returns an Integer == fixnum_max when (fixnum_max * 2) >> 1 and n > 0" do
+ it "returns a Fixnum == fixnum_max when (fixnum_max * 2) >> 1 and n > 0" do
result = (fixnum_max * 2) >> 1
result.should be_an_instance_of(Integer)
result.should == fixnum_max
end
- it "returns an Integer == fixnum_min when (fixnum_min * 2) >> 1 and n < 0" do
+ it "returns a Fixnum == fixnum_min when (fixnum_min * 2) >> 1 and n < 0" do
result = (fixnum_min * 2) >> 1
result.should be_an_instance_of(Integer)
result.should == fixnum_min
diff --git a/spec/ruby/core/integer/shared/exponent.rb b/spec/ruby/core/integer/shared/exponent.rb
index f292cc2448..f949c514c8 100644
--- a/spec/ruby/core/integer/shared/exponent.rb
+++ b/spec/ruby/core/integer/shared/exponent.rb
@@ -47,7 +47,9 @@ describe :integer_exponent, shared: true do
end
it "returns Float::INFINITY when the number is too big" do
- 2.send(@method, 427387904).should == Float::INFINITY
+ -> {
+ 2.send(@method, 427387904).should == Float::INFINITY
+ }.should complain(/warning: in a\*\*b, b may be too big/)
end
it "raises a ZeroDivisionError for 0 ** -1" do
@@ -105,7 +107,10 @@ describe :integer_exponent, shared: true do
end
it "switch to a Float when the values is too big" do
- flt = @bignum.send(@method, @bignum)
+ flt = nil
+ -> {
+ flt = @bignum.send(@method, @bignum)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
flt.should be_kind_of(Float)
flt.infinite?.should == 1
end
diff --git a/spec/ruby/core/integer/shared/next.rb b/spec/ruby/core/integer/shared/next.rb
index fd983d53ec..85b83d6965 100644
--- a/spec/ruby/core/integer/shared/next.rb
+++ b/spec/ruby/core/integer/shared/next.rb
@@ -1,25 +1,25 @@
describe :integer_next, shared: true do
- it "returns the next larger positive Integer" do
+ it "returns the next larger positive Fixnum" do
2.send(@method).should == 3
end
- it "returns the next larger negative Integer" do
+ it "returns the next larger negative Fixnum" do
(-2).send(@method).should == -1
end
- it "returns the next larger positive Integer" do
+ it "returns the next larger positive Bignum" do
bignum_value.send(@method).should == bignum_value(1)
end
- it "returns the next larger negative Integer" do
+ it "returns the next larger negative Bignum" do
(-bignum_value(1)).send(@method).should == -bignum_value
end
- it "overflows an Integer to an Integer" do
+ it "overflows a Fixnum to a Bignum" do
fixnum_max.send(@method).should == fixnum_max + 1
end
- it "underflows an Integer to an Integer" do
+ it "underflows a Bignum to a Fixnum" do
(fixnum_min - 1).send(@method).should == fixnum_min
end
end
diff --git a/spec/ruby/core/integer/to_r_spec.rb b/spec/ruby/core/integer/to_r_spec.rb
index ac998e2a30..7732bedca1 100644
--- a/spec/ruby/core/integer/to_r_spec.rb
+++ b/spec/ruby/core/integer/to_r_spec.rb
@@ -13,7 +13,7 @@ describe "Integer#to_r" do
298.to_r.denominator.should == 1
end
- it "works even if self is an Integer" do
+ it "works even if self is a Bignum" do
bignum = 99999**999
bignum.should be_an_instance_of(Integer)
bignum.to_r.should == Rational(bignum, 1)
diff --git a/spec/ruby/core/integer/uminus_spec.rb b/spec/ruby/core/integer/uminus_spec.rb
index efaed1d2a6..b6b110dec4 100644
--- a/spec/ruby/core/integer/uminus_spec.rb
+++ b/spec/ruby/core/integer/uminus_spec.rb
@@ -10,7 +10,7 @@ describe "Integer#-@" do
-8.send(:-@).should == 8
end
- it "negates self at Integer/Integer boundaries" do
+ it "negates self at Fixnum/Bignum boundaries" do
(-fixnum_max).should == (0 - fixnum_max)
(-fixnum_max).should < 0
(-fixnum_min).should == (0 - fixnum_min)