summaryrefslogtreecommitdiff
path: root/test/-ext-/bignum
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-11 21:39:55 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-11 21:39:55 +0000
commit0c9a719d7728e026e2bd4dfef61d940d3ca7248f (patch)
treeabf593edd8848f8f9e18699b07a11aacb2389da8 /test/-ext-/bignum
parenta338c4ed5d519f05bf1f9fcd6a7b237a3101df0a (diff)
* internal.h (INTEGER_PACK_NEGATIVE): Defined.
(rb_integer_unpack): sign argument removed. * bignum.c (rb_integer_unpack): sign argument removed. Non-negative integers generated by default. INTEGER_PACK_NEGATIVE flag is used to generate non-positive integers. * pack.c (pack_unpack): Follow the above change. * random.c (int_pair_to_real_inclusive): Ditto. (make_seed_value): Ditto. (mt_state): Ditto. (limited_big_rand): Ditto. * marshal.c (r_object0): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/-ext-/bignum')
-rw-r--r--test/-ext-/bignum/test_pack.rb45
1 files changed, 23 insertions, 22 deletions
diff --git a/test/-ext-/bignum/test_pack.rb b/test/-ext-/bignum/test_pack.rb
index 21abf093e5f..ea5dedd585a 100644
--- a/test/-ext-/bignum/test_pack.rb
+++ b/test/-ext-/bignum/test_pack.rb
@@ -13,6 +13,7 @@ class TestBignum < Test::Unit::TestCase
NATIVE_BYTE_ORDER = Integer::INTEGER_PACK_NATIVE_BYTE_ORDER
LITTLE_ENDIAN = Integer::INTEGER_PACK_LITTLE_ENDIAN
BIG_ENDIAN = Integer::INTEGER_PACK_BIG_ENDIAN
+ NEGATIVE = Integer::INTEGER_PACK_NEGATIVE
def test_pack_zero
assert_equal([0, ""], 0.test_pack(0, 1, 0, BIG_ENDIAN))
@@ -117,48 +118,48 @@ class TestBignum < Test::Unit::TestCase
end
def test_unpack_zero
- assert_equal(0, Integer.test_unpack(0, "", 0, 1, 0, BIG_ENDIAN))
+ assert_equal(0, Integer.test_unpack("", 0, 1, 0, BIG_ENDIAN))
end
def test_unpack_argument_check
- assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 2, 1, 0, MSBYTE_FIRST) }
- assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 0, MSWORD_FIRST) }
- assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 0, 0, BIG_ENDIAN) }
- assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 8, BIG_ENDIAN) }
+ assert_raise(ArgumentError) { Integer.test_unpack("x", 2, 1, 0, MSBYTE_FIRST) }
+ assert_raise(ArgumentError) { Integer.test_unpack("x", 1, 1, 0, MSWORD_FIRST) }
+ assert_raise(ArgumentError) { Integer.test_unpack("x", 1, 0, 0, BIG_ENDIAN) }
+ assert_raise(ArgumentError) { Integer.test_unpack("x", 1, 1, 8, BIG_ENDIAN) }
# assume sizeof(ssize_t) == sizeof(intptr_t)
- assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
+ assert_raise(ArgumentError) { Integer.test_unpack("x", 1, 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
end
def test_unpack_wordsize
- assert_equal(1, Integer.test_unpack(1, "\x01", 1, 1, 0, BIG_ENDIAN))
- assert_equal(1, Integer.test_unpack(1, "\x00\x01", 1, 2, 0, BIG_ENDIAN))
- assert_equal(1, Integer.test_unpack(1, "\x00\x00\x01", 1, 3, 0, BIG_ENDIAN))
- assert_equal(1, Integer.test_unpack(1, "\x01", 1, 1, 0, LITTLE_ENDIAN))
- assert_equal(1, Integer.test_unpack(1, "\x01\x00", 1, 2, 0, LITTLE_ENDIAN))
- assert_equal(1, Integer.test_unpack(1, "\x01\x00\x00", 1, 3, 0, LITTLE_ENDIAN))
+ assert_equal(1, Integer.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN))
+ assert_equal(1, Integer.test_unpack("\x00\x01", 1, 2, 0, BIG_ENDIAN))
+ assert_equal(1, Integer.test_unpack("\x00\x00\x01", 1, 3, 0, BIG_ENDIAN))
+ assert_equal(1, Integer.test_unpack("\x01", 1, 1, 0, LITTLE_ENDIAN))
+ assert_equal(1, Integer.test_unpack("\x01\x00", 1, 2, 0, LITTLE_ENDIAN))
+ assert_equal(1, Integer.test_unpack("\x01\x00\x00", 1, 3, 0, LITTLE_ENDIAN))
end
def test_unpack_wordorder_and_endian
- assert_equal(0x01020304, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
- assert_equal(0x02010403, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
- assert_equal(0x03040102, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
- assert_equal(0x04030201, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
+ assert_equal(0x01020304, Integer.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
+ assert_equal(0x02010403, Integer.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
+ assert_equal(0x03040102, Integer.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
+ assert_equal(0x04030201, Integer.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
end
def test_unpack_native_endian
- assert_equal("\x12\x34".unpack("S!")[0], Integer.test_unpack(1, "\x12\x34", 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
+ assert_equal("\x12\x34".unpack("S!")[0], Integer.test_unpack("\x12\x34", 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
end
def test_unpack_nail
- assert_equal(0b100011, Integer.test_unpack(1, "\x01\x00\x00\x00\x01\x01", 6, 1, 7, BIG_ENDIAN))
- assert_equal(0x12345678, Integer.test_unpack(1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 4, BIG_ENDIAN))
- assert_equal(0x12345678, Integer.test_unpack(1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4, 2, 8, BIG_ENDIAN))
+ assert_equal(0b100011, Integer.test_unpack("\x01\x00\x00\x00\x01\x01", 6, 1, 7, BIG_ENDIAN))
+ assert_equal(0x12345678, Integer.test_unpack("\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 4, BIG_ENDIAN))
+ assert_equal(0x12345678, Integer.test_unpack("\x00\x12\x00\x34\x00\x56\x00\x78", 4, 2, 8, BIG_ENDIAN))
end
def test_unpack_sign
- assert_equal(-1, Integer.test_unpack(-1, "\x01", 1, 1, 0, BIG_ENDIAN))
- assert_equal(-0x8070605040302010, Integer.test_unpack(-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 0, BIG_ENDIAN))
+ assert_equal(-1, Integer.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN|NEGATIVE))
+ assert_equal(-0x8070605040302010, Integer.test_unpack("\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 0, BIG_ENDIAN|NEGATIVE))
end
end