diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-12-21 01:16:26 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-12-21 01:19:55 +0900 |
commit | 9c73c756244fa27ffa99d81dcc73a4ad14198002 (patch) | |
tree | 14b0ea9059b8c31e276531a1df712ead4e158cdb /spec/ruby/core/integer | |
parent | fb8f011422c645ebe29e94c3fb2079af73d1d35f (diff) | |
download | ruby-9c73c756244fa27ffa99d81dcc73a4ad14198002.tar.gz |
Use Integer instead of Fixnum/Bignum
Diffstat (limited to 'spec/ruby/core/integer')
-rw-r--r-- | spec/ruby/core/integer/coerce_spec.rb | 20 | ||||
-rw-r--r-- | spec/ruby/core/integer/comparison_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/core/integer/constants_spec.rb | 32 | ||||
-rw-r--r-- | spec/ruby/core/integer/denominator_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/integer/div_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/integer/downto_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/integer/element_reference_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/integer/even_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/integer/gcd_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/core/integer/gcdlcm_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/core/integer/lcm_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/core/integer/left_shift_spec.rb | 20 | ||||
-rw-r--r-- | spec/ruby/core/integer/right_shift_spec.rb | 18 | ||||
-rw-r--r-- | spec/ruby/core/integer/shared/equal.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/integer/shared/next.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/integer/to_r_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/integer/uminus_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/integer/upto_spec.rb | 2 |
18 files changed, 80 insertions, 78 deletions
diff --git a/spec/ruby/core/integer/coerce_spec.rb b/spec/ruby/core/integer/coerce_spec.rb index 9a19baf2ea..4d540bfb87 100644 --- a/spec/ruby/core/integer/coerce_spec.rb +++ b/spec/ruby/core/integer/coerce_spec.rb @@ -4,10 +4,10 @@ require 'bigdecimal' describe "Integer#coerce" do context "fixnum" do - describe "when given a Fixnum" do - it "returns an array containing two Fixnums" do + describe "when given an Integer" do + it "returns an array containing two Integers" do 1.coerce(2).should == [2, 1] - 1.coerce(2).map { |i| i.class }.should == [Fixnum, Fixnum] + 1.coerce(2).map { |i| i.class }.should == [Integer, Integer] end end @@ -42,26 +42,26 @@ describe "Integer#coerce" do end context "bignum" do - it "coerces other to a Bignum and returns [other, self] when passed a Fixnum" do + it "coerces other to an Integer and returns [other, self] when passed an Integer" do a = bignum_value ary = a.coerce(2) - ary[0].should be_kind_of(Bignum) - ary[1].should be_kind_of(Bignum) + ary[0].should be_kind_of(Integer) + ary[1].should be_kind_of(Integer) ary.should == [2, a] end - it "returns [other, self] when passed a Bignum" do + it "returns [other, self] when passed an Integer" do a = bignum_value b = bignum_value ary = a.coerce(b) - ary[0].should be_kind_of(Bignum) - ary[1].should be_kind_of(Bignum) + ary[0].should be_kind_of(Integer) + ary[1].should be_kind_of(Integer) ary.should == [b, a] end - it "raises a TypeError when not passed a Fixnum or Bignum" do + it "raises a TypeError when not passed an Integer" 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 db050aa8b9..a0d8d24119 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 a Fixnum" do + describe "with an Integer" 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 a Bignum" do + describe "with an Integer" 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 @@ -116,7 +116,7 @@ describe "Integer#<=>" do describe "with an Object" do before :each do @big = bignum_value - @num = mock("value for Bignum#<=>") + @num = mock("value for Integer#<=>") end it "calls #coerce on other" do @@ -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 a Bignum" do + it "returns 1 when self is Infinity and other is an Integer" 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 3b8b01e330..35601f82b9 100644 --- a/spec/ruby/core/integer/constants_spec.rb +++ b/spec/ruby/core/integer/constants_spec.rb @@ -1,25 +1,27 @@ require_relative '../../spec_helper' -describe "Fixnum" do - it "is unified into Integer" do - suppress_warning do - Fixnum.should equal(Integer) +ruby_version_is ""..."3.0" do + describe "Fixnum" do + it "is unified into Integer" do + suppress_warning do + Fixnum.should equal(Integer) + end end - end - it "is deprecated" do - -> { Fixnum }.should complain(/constant ::Fixnum is deprecated/) + it "is deprecated" do + -> { Fixnum }.should complain(/constant ::Fixnum is deprecated/) + end end -end -describe "Bignum" do - it "is unified into Integer" do - suppress_warning do - Bignum.should equal(Integer) + describe "Bignum" do + it "is unified into Integer" do + suppress_warning do + Bignum.should equal(Integer) + end end - end - it "is deprecated" do - -> { Bignum }.should complain(/constant ::Bignum is deprecated/) + it "is deprecated" do + -> { Bignum }.should complain(/constant ::Bignum is deprecated/) + end end end diff --git a/spec/ruby/core/integer/denominator_spec.rb b/spec/ruby/core/integer/denominator_spec.rb index c1477d0757..d19b8175a3 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, # Bignum + 99999999**99, # Integer -99999**621, # Negative BigNum 0, 1 diff --git a/spec/ruby/core/integer/div_spec.rb b/spec/ruby/core/integer/div_spec.rb index 087d012fe0..bc1c4363d4 100644 --- a/spec/ruby/core/integer/div_spec.rb +++ b/spec/ruby/core/integer/div_spec.rb @@ -36,7 +36,7 @@ describe "Integer#div" do 10.div(y).should == result end - it "coerces self and the given argument to Floats and returns self divided by other as Fixnum" do + it "coerces self and the given argument to Floats and returns self divided by other as Integer" do 1.div(0.2).should == 5 1.div(0.16).should == 6 1.div(0.169).should == 5 diff --git a/spec/ruby/core/integer/downto_spec.rb b/spec/ruby/core/integer/downto_spec.rb index af7a7e36b9..987704b02e 100644 --- a/spec/ruby/core/integer/downto_spec.rb +++ b/spec/ruby/core/integer/downto_spec.rb @@ -1,6 +1,6 @@ require_relative '../../spec_helper' -describe "Integer#downto [stop] when self and stop are Fixnums" do +describe "Integer#downto [stop] when self and stop are Integers" do it "does not yield when stop is greater than self" do result = [] 5.downto(6) { |x| result << x } diff --git a/spec/ruby/core/integer/element_reference_spec.rb b/spec/ruby/core/integer/element_reference_spec.rb index 4c236a11e7..6e65c50254 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 a Bignum and returns 0" do + it "calls #to_int to coerce a String to an Integer 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 a Bignum" do + it "returns 0 when passed a Float in the range of an Integer" do 3[bignum_value.to_f].should == 0 end diff --git a/spec/ruby/core/integer/even_spec.rb b/spec/ruby/core/integer/even_spec.rb index a314cc6b19..a93f54c74e 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 a Fixnum when it is an even number" do + it "returns true for an Integer 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 a Bignum when it is an even number" do + it "returns true for an Integer 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 8aa654a16a..82086d742a 100644 --- a/spec/ruby/core/integer/gcd_spec.rb +++ b/spec/ruby/core/integer/gcd_spec.rb @@ -31,15 +31,15 @@ describe "Integer#gcd" do -100.gcd(-100).should == 100 end - it "accepts a Bignum argument" do + it "accepts an Integer argument" do bignum = 9999**99 - bignum.should be_kind_of(Bignum) + bignum.should be_kind_of(Integer) 99.gcd(bignum).should == 99 end - it "works if self is a Bignum" do + it "works if self is an Integer" do bignum = 9999**99 - bignum.should be_kind_of(Bignum) + bignum.should be_kind_of(Integer) bignum.gcd(99).should == 99 end diff --git a/spec/ruby/core/integer/gcdlcm_spec.rb b/spec/ruby/core/integer/gcdlcm_spec.rb index 5b3669e62a..2915750f88 100644 --- a/spec/ruby/core/integer/gcdlcm_spec.rb +++ b/spec/ruby/core/integer/gcdlcm_spec.rb @@ -26,15 +26,15 @@ describe "Integer#gcdlcm" do 200.gcdlcm(20)[1].should == 200.lcm(20) end - it "accepts a Bignum argument" do + it "accepts an Integer argument" do bignum = 91999**99 - bignum.should be_kind_of(Bignum) + bignum.should be_kind_of(Integer) 99.gcdlcm(bignum).should == [99.gcd(bignum), 99.lcm(bignum)] end - it "works if self is a Bignum" do + it "works if self is an Integer" do bignum = 9999**89 - bignum.should be_kind_of(Bignum) + bignum.should be_kind_of(Integer) bignum.gcdlcm(99).should == [bignum.gcd(99), bignum.lcm(99)] end diff --git a/spec/ruby/core/integer/lcm_spec.rb b/spec/ruby/core/integer/lcm_spec.rb index 77d3ad3488..39976ea474 100644 --- a/spec/ruby/core/integer/lcm_spec.rb +++ b/spec/ruby/core/integer/lcm_spec.rb @@ -31,15 +31,15 @@ describe "Integer#lcm" do -100.lcm(-100).should == 100 end - it "accepts a Bignum argument" do + it "accepts an Integer argument" do bignum = 9999**99 - bignum.should be_kind_of(Bignum) + bignum.should be_kind_of(Integer) 99.lcm(bignum).should == bignum end - it "works if self is a Bignum" do + it "works if self is an Integer" do bignum = 9999**99 - bignum.should be_kind_of(Bignum) + bignum.should be_kind_of(Integer) bignum.lcm(99).should == bignum end diff --git a/spec/ruby/core/integer/left_shift_spec.rb b/spec/ruby/core/integer/left_shift_spec.rb index f9a8c9bbd1..d2ffe4bbeb 100644 --- a/spec/ruby/core/integer/left_shift_spec.rb +++ b/spec/ruby/core/integer/left_shift_spec.rb @@ -52,19 +52,19 @@ describe "Integer#<< (with n << m)" do (-7 << -64).should == -1 end - it "returns 0 when m < 0 and m is a Bignum" do + it "returns 0 when m < 0 and m is an Integer" do (3 << -bignum_value).should == 0 end - it "returns an Bignum == fixnum_max * 2 when fixnum_max << 1 and n > 0" do + it "returns an Integer == fixnum_max * 2 when fixnum_max << 1 and n > 0" do result = fixnum_max << 1 - result.should be_an_instance_of(Bignum) + result.should be_an_instance_of(Integer) result.should == fixnum_max * 2 end - it "returns an Bignum == fixnum_min * 2 when fixnum_min << 1 and n < 0" do + it "returns an Integer == fixnum_min * 2 when fixnum_min << 1 and n < 0" do result = fixnum_min << 1 - result.should be_an_instance_of(Bignum) + result.should be_an_instance_of(Integer) result.should == fixnum_min * 2 end @@ -127,19 +127,19 @@ describe "Integer#<< (with n << m)" do (@bignum << -68).should == 0 end - it "returns 0 when m < 0 and m is a Bignum" do + it "returns 0 when m < 0 and m is an Integer" do (@bignum << -bignum_value).should == 0 end - it "returns a Fixnum == fixnum_max when (fixnum_max * 2) << -1 and n > 0" do + it "returns an Integer == fixnum_max when (fixnum_max * 2) << -1 and n > 0" do result = (fixnum_max * 2) << -1 - result.should be_an_instance_of(Fixnum) + result.should be_an_instance_of(Integer) result.should == fixnum_max end - it "returns a Fixnum == fixnum_min when (fixnum_min * 2) << -1 and n < 0" do + it "returns an Integer == fixnum_min when (fixnum_min * 2) << -1 and n < 0" do result = (fixnum_min * 2) << -1 - result.should be_an_instance_of(Fixnum) + result.should be_an_instance_of(Integer) result.should == fixnum_min end diff --git a/spec/ruby/core/integer/right_shift_spec.rb b/spec/ruby/core/integer/right_shift_spec.rb index 1eac6cb5bc..62cbe862b9 100644 --- a/spec/ruby/core/integer/right_shift_spec.rb +++ b/spec/ruby/core/integer/right_shift_spec.rb @@ -56,15 +56,15 @@ describe "Integer#>> (with n >> m)" do (3 >> bignum_value).should == 0 end - it "returns an Bignum == fixnum_max * 2 when fixnum_max >> -1 and n > 0" do + it "returns an Integer == fixnum_max * 2 when fixnum_max >> -1 and n > 0" do result = fixnum_max >> -1 - result.should be_an_instance_of(Bignum) + result.should be_an_instance_of(Integer) result.should == fixnum_max * 2 end - it "returns an Bignum == fixnum_min * 2 when fixnum_min >> -1 and n < 0" do + it "returns an Integer == fixnum_min * 2 when fixnum_min >> -1 and n < 0" do result = fixnum_min >> -1 - result.should be_an_instance_of(Bignum) + result.should be_an_instance_of(Integer) result.should == fixnum_min * 2 end @@ -153,19 +153,19 @@ describe "Integer#>> (with n >> m)" do (@bignum >> 68).should == 0 end - it "returns 0 when m is a Bignum" do + it "returns 0 when m is an Integer" do (@bignum >> bignum_value).should == 0 end - it "returns a Fixnum == fixnum_max when (fixnum_max * 2) >> 1 and n > 0" do + it "returns an Integer == fixnum_max when (fixnum_max * 2) >> 1 and n > 0" do result = (fixnum_max * 2) >> 1 - result.should be_an_instance_of(Fixnum) + result.should be_an_instance_of(Integer) result.should == fixnum_max end - it "returns a Fixnum == fixnum_min when (fixnum_min * 2) >> 1 and n < 0" do + it "returns an Integer == fixnum_min when (fixnum_min * 2) >> 1 and n < 0" do result = (fixnum_min * 2) >> 1 - result.should be_an_instance_of(Fixnum) + result.should be_an_instance_of(Integer) result.should == fixnum_min end diff --git a/spec/ruby/core/integer/shared/equal.rb b/spec/ruby/core/integer/shared/equal.rb index 4a5a236ffa..ecee17831c 100644 --- a/spec/ruby/core/integer/shared/equal.rb +++ b/spec/ruby/core/integer/shared/equal.rb @@ -4,7 +4,7 @@ describe :integer_equal, shared: true do 1.send(@method, 1).should == true 9.send(@method, 5).should == false - # Actually, these call Float#==, Bignum#== etc. + # Actually, these call Float#==, Integer#== etc. 9.send(@method, 9.0).should == true 9.send(@method, 9.01).should == false diff --git a/spec/ruby/core/integer/shared/next.rb b/spec/ruby/core/integer/shared/next.rb index 85b83d6965..fd983d53ec 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 Fixnum" do + it "returns the next larger positive Integer" do 2.send(@method).should == 3 end - it "returns the next larger negative Fixnum" do + it "returns the next larger negative Integer" do (-2).send(@method).should == -1 end - it "returns the next larger positive Bignum" do + it "returns the next larger positive Integer" do bignum_value.send(@method).should == bignum_value(1) end - it "returns the next larger negative Bignum" do + it "returns the next larger negative Integer" do (-bignum_value(1)).send(@method).should == -bignum_value end - it "overflows a Fixnum to a Bignum" do + it "overflows an Integer to an Integer" do fixnum_max.send(@method).should == fixnum_max + 1 end - it "underflows a Bignum to a Fixnum" do + it "underflows an Integer to an Integer" 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 4a40575b7f..ac998e2a30 100644 --- a/spec/ruby/core/integer/to_r_spec.rb +++ b/spec/ruby/core/integer/to_r_spec.rb @@ -13,9 +13,9 @@ describe "Integer#to_r" do 298.to_r.denominator.should == 1 end - it "works even if self is a Bignum" do + it "works even if self is an Integer" do bignum = 99999**999 - bignum.should be_an_instance_of(Bignum) + bignum.should be_an_instance_of(Integer) bignum.to_r.should == Rational(bignum, 1) end diff --git a/spec/ruby/core/integer/uminus_spec.rb b/spec/ruby/core/integer/uminus_spec.rb index b6b110dec4..efaed1d2a6 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 Fixnum/Bignum boundaries" do + it "negates self at Integer/Integer boundaries" do (-fixnum_max).should == (0 - fixnum_max) (-fixnum_max).should < 0 (-fixnum_min).should == (0 - fixnum_min) diff --git a/spec/ruby/core/integer/upto_spec.rb b/spec/ruby/core/integer/upto_spec.rb index 6049eb173e..dd6995e94b 100644 --- a/spec/ruby/core/integer/upto_spec.rb +++ b/spec/ruby/core/integer/upto_spec.rb @@ -1,6 +1,6 @@ require_relative '../../spec_helper' -describe "Integer#upto [stop] when self and stop are Fixnums" do +describe "Integer#upto [stop] when self and stop are Integers" do it "does not yield when stop is less than self" do result = [] 5.upto(4) { |x| result << x } |