envutil.rb defines Integer::{FIXNUM_MIN,FIXNUM_MAX}.

* test/lib/envutil.rb: Define Integer::{FIXNUM_MIN,FIXNUM_MAX}.

* test/ruby/test_bignum.rb: Use Integer::{FIXNUM_MIN,FIXNUM_MAX}.

* test/ruby/test_bignum.rb: Ditto.

* test/ruby/test_integer_comb.rb: Ditto.

* test/ruby/test_marshal.rb: Ditto.

* test/ruby/test_optimization.rb: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2016-05-01 15:16:17 +00:00
parent f98c9a0aa6
commit de2f7416d2
7 changed files with 32 additions and 33 deletions

View file

@ -1,3 +1,17 @@
Mon May 2 00:06:04 2016 Tanaka Akira <akr@fsij.org>
* test/lib/envutil.rb: Define Integer::{FIXNUM_MIN,FIXNUM_MAX}.
* test/ruby/test_bignum.rb: Use Integer::{FIXNUM_MIN,FIXNUM_MAX}.
* test/ruby/test_bignum.rb: Ditto.
* test/ruby/test_integer_comb.rb: Ditto.
* test/ruby/test_marshal.rb: Ditto.
* test/ruby/test_optimization.rb: Ditto.
Sun May 1 23:59:59 2016 Kenta Murata <mrkn@mrkn.jp> Sun May 1 23:59:59 2016 Kenta Murata <mrkn@mrkn.jp>
* array.c (rb_ary_sum): fix for mathn * array.c (rb_ary_sum): fix for mathn

View file

@ -3,6 +3,12 @@
require "open3" require "open3"
require "timeout" require "timeout"
require_relative "find_executable" require_relative "find_executable"
require "rbconfig/sizeof"
class Integer
FIXNUM_MIN = -(1 << (8 * RbConfig::SIZEOF['long'] - 2))
FIXNUM_MAX = (1 << (8 * RbConfig::SIZEOF['long'] - 2)) - 1
end
module EnvUtil module EnvUtil
def rubybin def rubybin

View file

@ -2,16 +2,13 @@
require 'test/unit' require 'test/unit'
class TestBignum < Test::Unit::TestCase class TestBignum < Test::Unit::TestCase
b = 2**64 FIXNUM_MIN = Integer::FIXNUM_MIN
b *= b until Bignum === b FIXNUM_MAX = Integer::FIXNUM_MAX
f = b BIGNUM_MIN = FIXNUM_MAX + 1
while Bignum === f-1 b = BIGNUM_MIN
f >>= 1
end
BIGNUM_MIN = f
FIXNUM_MAX = f-1
f = BIGNUM_MIN
n = 0 n = 0
until f == 0 until f == 0
f >>= 1 f >>= 1

View file

@ -2,7 +2,6 @@
require 'test/unit' require 'test/unit'
EnvUtil.suppress_warning {require 'continuation'} EnvUtil.suppress_warning {require 'continuation'}
require 'stringio' require 'stringio'
require "rbconfig/sizeof"
class TestEnumerable < Test::Unit::TestCase class TestEnumerable < Test::Unit::TestCase
def setup def setup
@ -185,8 +184,8 @@ class TestEnumerable < Test::Unit::TestCase
assert_equal(nil, @empty.inject() {9}) assert_equal(nil, @empty.inject() {9})
end end
FIXNUM_MIN = -(1 << (8 * RbConfig::SIZEOF['long'] - 2)) FIXNUM_MIN = Integer::FIXNUM_MIN
FIXNUM_MAX = (1 << (8 * RbConfig::SIZEOF['long'] - 2)) - 1 FIXNUM_MAX = Integer::FIXNUM_MAX
def test_inject_array_mul def test_inject_array_mul
assert_equal(nil, [].inject(:*)) assert_equal(nil, [].inject(:*))

View file

@ -110,12 +110,8 @@ class TestIntegerComb < Test::Unit::TestCase
#VS.concat VS.find_all {|v| Fixnum === v }.map {|v| 0x4000000000000000.coerce(v)[0] } #VS.concat VS.find_all {|v| Fixnum === v }.map {|v| 0x4000000000000000.coerce(v)[0] }
#VS.sort! {|a, b| a.abs <=> b.abs } #VS.sort! {|a, b| a.abs <=> b.abs }
min = -1 FIXNUM_MIN = Integer::FIXNUM_MIN
min *= 2 while min.class == Fixnum FIXNUM_MAX = Integer::FIXNUM_MAX
FIXNUM_MIN = min/2
max = 1
max *= 2 while (max-1).class == Fixnum
FIXNUM_MAX = max/2-1
def test_fixnum_range def test_fixnum_range
assert_instance_of(Bignum, FIXNUM_MIN-1) assert_instance_of(Bignum, FIXNUM_MIN-1)

View file

@ -622,8 +622,7 @@ class TestMarshal < Test::Unit::TestCase
def test_untainted_numeric def test_untainted_numeric
bug8945 = '[ruby-core:57346] [Bug #8945] Numerics never be tainted' bug8945 = '[ruby-core:57346] [Bug #8945] Numerics never be tainted'
b = 1 << 32 b = Integer::FIXNUM_MAX + 1
b *= b until Bignum === b
tainted = [0, 1.0, 1.72723e-77, b].select do |x| tainted = [0, 1.0, 1.72723e-77, b].select do |x|
Marshal.load(Marshal.dump(x).taint).tainted? Marshal.load(Marshal.dump(x).taint).tainted?
end end

View file

@ -3,20 +3,8 @@ require 'test/unit'
require 'objspace' require 'objspace'
class TestRubyOptimization < Test::Unit::TestCase class TestRubyOptimization < Test::Unit::TestCase
FIXNUM_MAX = Integer::FIXNUM_MAX
BIGNUM_POS_MIN_32 = 1073741824 # 2 ** 30 FIXNUM_MIN = Integer::FIXNUM_MIN
if BIGNUM_POS_MIN_32.kind_of?(Fixnum)
FIXNUM_MAX = 4611686018427387903 # 2 ** 62 - 1
else
FIXNUM_MAX = 1073741823 # 2 ** 30 - 1
end
BIGNUM_NEG_MAX_32 = -1073741825 # -2 ** 30 - 1
if BIGNUM_NEG_MAX_32.kind_of?(Fixnum)
FIXNUM_MIN = -4611686018427387904 # -2 ** 62
else
FIXNUM_MIN = -1073741824 # -2 ** 30
end
def assert_redefine_method(klass, method, code, msg = nil) def assert_redefine_method(klass, method, code, msg = nil)
assert_separately([], <<-"end;")# do assert_separately([], <<-"end;")# do