diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-22 11:38:19 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-22 11:38:19 +0000 |
commit | 972ae3e5389d4b35d6252b05e3bc0a4f22f29fc7 (patch) | |
tree | 160a5dfd5197e2d96ff7175a0a3bbaacb6344b88 /test/-ext-/bignum | |
parent | 8f0c3ff6e49fad5263f9be52946e1c13f9bcf021 (diff) | |
download | ruby-972ae3e5389d4b35d6252b05e3bc0a4f22f29fc7.tar.gz |
* bignum.c (bary_unpack_internal): Specialized unpacker implemented.
(bary_unpack): Support INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION.
(rb_integer_unpack): Support INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/-ext-/bignum')
-rw-r--r-- | test/-ext-/bignum/test_pack.rb | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/test/-ext-/bignum/test_pack.rb b/test/-ext-/bignum/test_pack.rb index fddc69b792..e5fb358ce8 100644 --- a/test/-ext-/bignum/test_pack.rb +++ b/test/-ext-/bignum/test_pack.rb @@ -259,6 +259,27 @@ class TestBignum < Test::Unit::TestCase assert_equal(-0x8070605040302010, Integer.test_unpack("\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 0, BIG_ENDIAN|NEGATIVE)) end + def test_unpack_orders + [MSWORD_FIRST, LSWORD_FIRST].each {|word_order| + [MSBYTE_FIRST, LSBYTE_FIRST, NATIVE_BYTE_ORDER].each {|byte_order| + 1.upto(16) {|wordsize| + 1.upto(20) {|numwords| + w = numwords*wordsize + ary = [] + 0.upto(w) {|i| + ary << ((i+1) % 256); + } + str = ary.pack("C*") + flags = word_order|byte_order + assert_equal(Integer.test_unpack(str, numwords, wordsize, 0, flags|GENERIC), + Integer.test_unpack(str, numwords, wordsize, 0, flags), + "Integer.test_unpack(#{str.dump}, #{numwords}, #{wordsize}, 0, #{'%#x' % flags})") + } + } + } + } + end + def test_unpack2comp_single_byte assert_equal(-128, Integer.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN)) assert_equal( -2, Integer.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN)) @@ -292,8 +313,12 @@ class TestBignum < Test::Unit::TestCase def test_unpack2comp_negative_zero 0.upto(100) {|n| - assert_equal(-(256**n), Integer.test_unpack("\x00"*n, n, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE)) - assert_equal(-(256**n), Integer.test_unpack("\x00"*n, n, 1, 0, TWOCOMP|LITTLE_ENDIAN|NEGATIVE)) + str = "\x00"*n + flags = TWOCOMP|BIG_ENDIAN|NEGATIVE + assert_equal(-(256**n), Integer.test_unpack(str, n, 1, 0, flags)) + flags = TWOCOMP|LITTLE_ENDIAN|NEGATIVE + assert_equal(-(256**n), Integer.test_unpack(str, n, 1, 0, flags), + "Integer.test_unpack(#{str.dump}, #{n}, 1, 0, #{'%#x' % flags})") } end end |