mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Get rid of defining methods for tests in core classes
Not to interfere in other tests.
This commit is contained in:
parent
161a20df28
commit
590dc06e38
Notes:
git
2021-01-09 22:38:31 +09:00
26 changed files with 406 additions and 392 deletions
|
@ -1,7 +1,7 @@
|
|||
#include "ruby/ruby.h"
|
||||
|
||||
static VALUE
|
||||
ary_resize(VALUE ary, VALUE len)
|
||||
ary_resize(VALUE klass, VALUE ary, VALUE len)
|
||||
{
|
||||
rb_ary_resize(ary, NUM2LONG(len));
|
||||
return ary;
|
||||
|
@ -10,5 +10,7 @@ ary_resize(VALUE ary, VALUE len)
|
|||
void
|
||||
Init_resize(void)
|
||||
{
|
||||
rb_define_method(rb_cArray, "__resize__", ary_resize, 1);
|
||||
VALUE mBug = rb_define_module("Bug");
|
||||
VALUE klass = rb_define_class_under(mBug, "Array", rb_cObject);
|
||||
rb_define_singleton_method(klass, "__resize__", ary_resize, 2);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ big(VALUE x)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
big2str_generic(VALUE x, VALUE vbase)
|
||||
big2str_generic(VALUE klass, VALUE x, VALUE vbase)
|
||||
{
|
||||
int base = NUM2INT(vbase);
|
||||
if (base < 2 || 36 < base)
|
||||
|
@ -23,7 +23,7 @@ big2str_generic(VALUE x, VALUE vbase)
|
|||
#define POW2_P(x) (((x)&((x)-1))==0)
|
||||
|
||||
static VALUE
|
||||
big2str_poweroftwo(VALUE x, VALUE vbase)
|
||||
big2str_poweroftwo(VALUE klass, VALUE x, VALUE vbase)
|
||||
{
|
||||
int base = NUM2INT(vbase);
|
||||
if (base < 2 || 36 < base || !POW2_P(base))
|
||||
|
@ -33,7 +33,7 @@ big2str_poweroftwo(VALUE x, VALUE vbase)
|
|||
|
||||
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
|
||||
static VALUE
|
||||
big2str_gmp(VALUE x, VALUE vbase)
|
||||
big2str_gmp(VALUE klass, VALUE x, VALUE vbase)
|
||||
{
|
||||
int base = NUM2INT(vbase);
|
||||
if (base < 2 || 36 < base)
|
||||
|
@ -47,7 +47,7 @@ big2str_gmp(VALUE x, VALUE vbase)
|
|||
void
|
||||
Init_big2str(VALUE klass)
|
||||
{
|
||||
rb_define_method(rb_cInteger, "big2str_generic", big2str_generic, 1);
|
||||
rb_define_method(rb_cInteger, "big2str_poweroftwo", big2str_poweroftwo, 1);
|
||||
rb_define_method(rb_cInteger, "big2str_gmp", big2str_gmp, 1);
|
||||
rb_define_singleton_method(klass, "big2str_generic", big2str_generic, 2);
|
||||
rb_define_singleton_method(klass, "big2str_poweroftwo", big2str_poweroftwo, 2);
|
||||
rb_define_singleton_method(klass, "big2str_gmp", big2str_gmp, 2);
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ big(VALUE x)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
divrem_normal(VALUE x, VALUE y)
|
||||
divrem_normal(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
return rb_big_norm(rb_big_divrem_normal(big(x), big(y)));
|
||||
}
|
||||
|
||||
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
|
||||
static VALUE
|
||||
divrem_gmp(VALUE x, VALUE y)
|
||||
divrem_gmp(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
return rb_big_norm(rb_big_divrem_gmp(big(x), big(y)));
|
||||
}
|
||||
|
@ -30,6 +30,6 @@ divrem_gmp(VALUE x, VALUE y)
|
|||
void
|
||||
Init_div(VALUE klass)
|
||||
{
|
||||
rb_define_method(rb_cInteger, "big_divrem_normal", divrem_normal, 1);
|
||||
rb_define_method(rb_cInteger, "big_divrem_gmp", divrem_gmp, 1);
|
||||
rb_define_singleton_method(klass, "big_divrem_normal", divrem_normal, 2);
|
||||
rb_define_singleton_method(klass, "big_divrem_gmp", divrem_gmp, 2);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "internal/bignum.h"
|
||||
|
||||
static VALUE
|
||||
rb_integer_pack_raw_m(VALUE val, VALUE buf, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags)
|
||||
rb_integer_pack_raw_m(VALUE klass, VALUE val, VALUE buf, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags)
|
||||
{
|
||||
int sign;
|
||||
size_t numwords = 0;
|
||||
|
@ -17,7 +17,7 @@ rb_integer_pack_raw_m(VALUE val, VALUE buf, VALUE numwords_arg, VALUE wordsize_a
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_integer_pack_m(VALUE val, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags)
|
||||
rb_integer_pack_m(VALUE klass, VALUE val, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags)
|
||||
{
|
||||
int sign;
|
||||
size_t numwords = NUM2SIZET(numwords_arg);
|
||||
|
@ -45,7 +45,7 @@ rb_integer_unpack_m(VALUE klass, VALUE buf, VALUE numwords, VALUE wordsize, VALU
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_integer_test_numbits_2comp_without_sign(VALUE val)
|
||||
rb_integer_test_numbits_2comp_without_sign(VALUE klass, VALUE val)
|
||||
{
|
||||
size_t size;
|
||||
int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val);
|
||||
|
@ -54,7 +54,7 @@ rb_integer_test_numbits_2comp_without_sign(VALUE val)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_integer_test_numbytes_2comp_with_sign(VALUE val)
|
||||
rb_integer_test_numbytes_2comp_with_sign(VALUE klass, VALUE val)
|
||||
{
|
||||
int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val);
|
||||
int nlz_bits;
|
||||
|
@ -67,21 +67,21 @@ rb_integer_test_numbytes_2comp_with_sign(VALUE val)
|
|||
void
|
||||
Init_intpack(VALUE klass)
|
||||
{
|
||||
rb_define_method(rb_cInteger, "test_pack_raw", rb_integer_pack_raw_m, 5);
|
||||
rb_define_method(rb_cInteger, "test_pack", rb_integer_pack_m, 4);
|
||||
rb_define_singleton_method(rb_cInteger, "test_unpack", rb_integer_unpack_m, 5);
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_MSWORD_FIRST", INT2NUM(INTEGER_PACK_MSWORD_FIRST));
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_LSWORD_FIRST", INT2NUM(INTEGER_PACK_LSWORD_FIRST));
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_MSBYTE_FIRST", INT2NUM(INTEGER_PACK_MSBYTE_FIRST));
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_LSBYTE_FIRST", INT2NUM(INTEGER_PACK_LSBYTE_FIRST));
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_NATIVE_BYTE_ORDER", INT2NUM(INTEGER_PACK_NATIVE_BYTE_ORDER));
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_2COMP", INT2NUM(INTEGER_PACK_2COMP));
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_LITTLE_ENDIAN", INT2NUM(INTEGER_PACK_LITTLE_ENDIAN));
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_BIG_ENDIAN", INT2NUM(INTEGER_PACK_BIG_ENDIAN));
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_FORCE_BIGNUM", INT2NUM(INTEGER_PACK_FORCE_BIGNUM));
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_NEGATIVE", INT2NUM(INTEGER_PACK_NEGATIVE));
|
||||
rb_define_const(rb_cInteger, "INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION", INT2NUM(INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION));
|
||||
rb_define_singleton_method(klass, "test_pack_raw", rb_integer_pack_raw_m, 6);
|
||||
rb_define_singleton_method(klass, "test_pack", rb_integer_pack_m, 5);
|
||||
rb_define_singleton_method(klass, "test_unpack", rb_integer_unpack_m, 5);
|
||||
rb_define_const(klass, "INTEGER_PACK_MSWORD_FIRST", INT2NUM(INTEGER_PACK_MSWORD_FIRST));
|
||||
rb_define_const(klass, "INTEGER_PACK_LSWORD_FIRST", INT2NUM(INTEGER_PACK_LSWORD_FIRST));
|
||||
rb_define_const(klass, "INTEGER_PACK_MSBYTE_FIRST", INT2NUM(INTEGER_PACK_MSBYTE_FIRST));
|
||||
rb_define_const(klass, "INTEGER_PACK_LSBYTE_FIRST", INT2NUM(INTEGER_PACK_LSBYTE_FIRST));
|
||||
rb_define_const(klass, "INTEGER_PACK_NATIVE_BYTE_ORDER", INT2NUM(INTEGER_PACK_NATIVE_BYTE_ORDER));
|
||||
rb_define_const(klass, "INTEGER_PACK_2COMP", INT2NUM(INTEGER_PACK_2COMP));
|
||||
rb_define_const(klass, "INTEGER_PACK_LITTLE_ENDIAN", INT2NUM(INTEGER_PACK_LITTLE_ENDIAN));
|
||||
rb_define_const(klass, "INTEGER_PACK_BIG_ENDIAN", INT2NUM(INTEGER_PACK_BIG_ENDIAN));
|
||||
rb_define_const(klass, "INTEGER_PACK_FORCE_BIGNUM", INT2NUM(INTEGER_PACK_FORCE_BIGNUM));
|
||||
rb_define_const(klass, "INTEGER_PACK_NEGATIVE", INT2NUM(INTEGER_PACK_NEGATIVE));
|
||||
rb_define_const(klass, "INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION", INT2NUM(INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION));
|
||||
|
||||
rb_define_method(rb_cInteger, "test_numbits_2comp_without_sign", rb_integer_test_numbits_2comp_without_sign, 0);
|
||||
rb_define_method(rb_cInteger, "test_numbytes_2comp_with_sign", rb_integer_test_numbytes_2comp_with_sign, 0);
|
||||
rb_define_singleton_method(klass, "test_numbits_2comp_without_sign", rb_integer_test_numbits_2comp_without_sign, 1);
|
||||
rb_define_singleton_method(klass, "test_numbytes_2comp_with_sign", rb_integer_test_numbytes_2comp_with_sign, 1);
|
||||
}
|
||||
|
|
|
@ -12,38 +12,38 @@ big(VALUE x)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
mul_normal(VALUE x, VALUE y)
|
||||
mul_normal(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
return rb_big_norm(rb_big_mul_normal(big(x), big(y)));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
sq_fast(VALUE x)
|
||||
sq_fast(VALUE klass, VALUE x)
|
||||
{
|
||||
return rb_big_norm(rb_big_sq_fast(big(x)));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
mul_balance(VALUE x, VALUE y)
|
||||
mul_balance(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
return rb_big_norm(rb_big_mul_balance(big(x), big(y)));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
mul_karatsuba(VALUE x, VALUE y)
|
||||
mul_karatsuba(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
return rb_big_norm(rb_big_mul_karatsuba(big(x), big(y)));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
mul_toom3(VALUE x, VALUE y)
|
||||
mul_toom3(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
return rb_big_norm(rb_big_mul_toom3(big(x), big(y)));
|
||||
}
|
||||
|
||||
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
|
||||
static VALUE
|
||||
mul_gmp(VALUE x, VALUE y)
|
||||
mul_gmp(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
return rb_big_norm(rb_big_mul_gmp(big(x), big(y)));
|
||||
}
|
||||
|
@ -54,12 +54,12 @@ mul_gmp(VALUE x, VALUE y)
|
|||
void
|
||||
Init_mul(VALUE klass)
|
||||
{
|
||||
rb_define_const(rb_cInteger, "SIZEOF_BDIGIT", INT2NUM(SIZEOF_BDIGIT));
|
||||
rb_define_const(rb_cInteger, "BITSPERDIG", INT2NUM(SIZEOF_BDIGIT * CHAR_BIT));
|
||||
rb_define_method(rb_cInteger, "big_mul_normal", mul_normal, 1);
|
||||
rb_define_method(rb_cInteger, "big_sq_fast", sq_fast, 0);
|
||||
rb_define_method(rb_cInteger, "big_mul_balance", mul_balance, 1);
|
||||
rb_define_method(rb_cInteger, "big_mul_karatsuba", mul_karatsuba, 1);
|
||||
rb_define_method(rb_cInteger, "big_mul_toom3", mul_toom3, 1);
|
||||
rb_define_method(rb_cInteger, "big_mul_gmp", mul_gmp, 1);
|
||||
rb_define_const(klass, "SIZEOF_BDIGIT", INT2NUM(SIZEOF_BDIGIT));
|
||||
rb_define_const(klass, "BITSPERDIG", INT2NUM(SIZEOF_BDIGIT * CHAR_BIT));
|
||||
rb_define_singleton_method(klass, "big_mul_normal", mul_normal, 2);
|
||||
rb_define_singleton_method(klass, "big_sq_fast", sq_fast, 1);
|
||||
rb_define_singleton_method(klass, "big_mul_balance", mul_balance, 2);
|
||||
rb_define_singleton_method(klass, "big_mul_karatsuba", mul_karatsuba, 2);
|
||||
rb_define_singleton_method(klass, "big_mul_toom3", mul_toom3, 2);
|
||||
rb_define_singleton_method(klass, "big_mul_gmp", mul_gmp, 2);
|
||||
}
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
#include "internal/bignum.h"
|
||||
|
||||
static VALUE
|
||||
str2big_poweroftwo(VALUE str, VALUE vbase, VALUE badcheck)
|
||||
str2big_poweroftwo(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
|
||||
{
|
||||
return rb_str2big_poweroftwo(str, NUM2INT(vbase), RTEST(badcheck));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
str2big_normal(VALUE str, VALUE vbase, VALUE badcheck)
|
||||
str2big_normal(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
|
||||
{
|
||||
return rb_str2big_normal(str, NUM2INT(vbase), RTEST(badcheck));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
str2big_karatsuba(VALUE str, VALUE vbase, VALUE badcheck)
|
||||
str2big_karatsuba(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
|
||||
{
|
||||
return rb_str2big_karatsuba(str, NUM2INT(vbase), RTEST(badcheck));
|
||||
}
|
||||
|
||||
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
|
||||
static VALUE
|
||||
str2big_gmp(VALUE str, VALUE vbase, VALUE badcheck)
|
||||
str2big_gmp(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
|
||||
{
|
||||
return rb_str2big_gmp(str, NUM2INT(vbase), RTEST(badcheck));
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ str2big_gmp(VALUE str, VALUE vbase, VALUE badcheck)
|
|||
void
|
||||
Init_str2big(VALUE klass)
|
||||
{
|
||||
rb_define_method(rb_cString, "str2big_poweroftwo", str2big_poweroftwo, 2);
|
||||
rb_define_method(rb_cString, "str2big_normal", str2big_normal, 2);
|
||||
rb_define_method(rb_cString, "str2big_karatsuba", str2big_karatsuba, 2);
|
||||
rb_define_method(rb_cString, "str2big_gmp", str2big_gmp, 2);
|
||||
rb_define_singleton_method(klass, "str2big_poweroftwo", str2big_poweroftwo, 3);
|
||||
rb_define_singleton_method(klass, "str2big_normal", str2big_normal, 3);
|
||||
rb_define_singleton_method(klass, "str2big_karatsuba", str2big_karatsuba, 3);
|
||||
rb_define_singleton_method(klass, "str2big_gmp", str2big_gmp, 3);
|
||||
}
|
||||
|
|
|
@ -15,5 +15,6 @@ ruby_fatal(VALUE obj, VALUE msg)
|
|||
void
|
||||
Init_rb_fatal(void)
|
||||
{
|
||||
rb_define_method(rb_mKernel, "rb_fatal", ruby_fatal, 1);
|
||||
VALUE mBug = rb_define_module("Bug");
|
||||
rb_define_singleton_method(mBug, "rb_fatal", ruby_fatal, 1);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ thread_runnable_sleep(VALUE thread, VALUE timeout)
|
|||
|
||||
rb_thread_call_without_gvl(native_sleep_callback, &timeval, RUBY_UBF_IO, NULL);
|
||||
|
||||
return thread;
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
struct loop_ctl {
|
||||
|
@ -65,12 +65,14 @@ thread_ubf_async_safe(VALUE thread, VALUE notify_fd)
|
|||
ctl.stop = 0;
|
||||
|
||||
rb_nogvl(do_loop, &ctl, stop_set, &ctl, RB_NOGVL_UBF_ASYNC_SAFE);
|
||||
return thread;
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
void
|
||||
Init_call_without_gvl(void)
|
||||
{
|
||||
rb_define_method(rb_cThread, "__runnable_sleep__", thread_runnable_sleep, 1);
|
||||
rb_define_method(rb_cThread, "__ubf_async_safe__", thread_ubf_async_safe, 1);
|
||||
VALUE mBug = rb_define_module("Bug");
|
||||
VALUE klass = rb_define_module_under(mBug, "Thread");
|
||||
rb_define_singleton_method(klass, "runnable_sleep", thread_runnable_sleep, 1);
|
||||
rb_define_singleton_method(klass, "ubf_async_safe", thread_ubf_async_safe, 1);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
#include "internal/numeric.h"
|
||||
|
||||
static VALUE
|
||||
int_bignum_p(VALUE self)
|
||||
int_bignum_p(VALUE klass, VALUE self)
|
||||
{
|
||||
return RB_TYPE_P(self, T_BIGNUM) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
int_fixnum_p(VALUE self)
|
||||
int_fixnum_p(VALUE klass, VALUE self)
|
||||
{
|
||||
return FIXNUM_P(self) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_int_to_bignum(VALUE x)
|
||||
rb_int_to_bignum(VALUE klass, VALUE x)
|
||||
{
|
||||
if (FIXNUM_P(x))
|
||||
x = rb_int2big(FIX2LONG(x));
|
||||
|
@ -21,7 +21,7 @@ rb_int_to_bignum(VALUE x)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
positive_pow(VALUE x, VALUE y)
|
||||
positive_pow(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
return rb_int_positive_pow(NUM2LONG(x), NUM2ULONG(y));
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ positive_pow(VALUE x, VALUE y)
|
|||
void
|
||||
Init_core_ext(VALUE klass)
|
||||
{
|
||||
rb_define_method(rb_cInteger, "bignum?", int_bignum_p, 0);
|
||||
rb_define_method(rb_cInteger, "fixnum?", int_fixnum_p, 0);
|
||||
rb_define_method(rb_cInteger, "to_bignum", rb_int_to_bignum, 0);
|
||||
rb_define_method(rb_cInteger, "positive_pow", positive_pow, 1);
|
||||
rb_define_singleton_method(klass, "bignum?", int_bignum_p, 1);
|
||||
rb_define_singleton_method(klass, "fixnum?", int_fixnum_p, 1);
|
||||
rb_define_singleton_method(klass, "to_bignum", rb_int_to_bignum, 1);
|
||||
rb_define_singleton_method(klass, "positive_pow", positive_pow, 2);
|
||||
}
|
||||
|
|
|
@ -14,14 +14,14 @@ big(VALUE x)
|
|||
#endif
|
||||
|
||||
static VALUE
|
||||
gcd_normal(VALUE x, VALUE y)
|
||||
gcd_normal(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
return rb_big_norm(rb_gcd_normal(rb_to_int(x), rb_to_int(y)));
|
||||
}
|
||||
|
||||
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
|
||||
static VALUE
|
||||
gcd_gmp(VALUE x, VALUE y)
|
||||
gcd_gmp(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
return rb_big_norm(rb_gcd_gmp(big(x), big(y)));
|
||||
}
|
||||
|
@ -36,10 +36,13 @@ s_rational_raw(VALUE klass, VALUE x, VALUE y)
|
|||
}
|
||||
|
||||
void
|
||||
Init_rational(VALUE klass)
|
||||
Init_rational(void)
|
||||
{
|
||||
rb_define_method(rb_cInteger, "gcd_normal", gcd_normal, 1);
|
||||
rb_define_method(rb_cInteger, "gcd_gmp", gcd_gmp, 1);
|
||||
VALUE mBug = rb_define_module("Bug");
|
||||
VALUE klass = rb_define_module_under(mBug, "Rational");
|
||||
|
||||
rb_define_singleton_method(rb_cRational, "raw", s_rational_raw, 2);
|
||||
rb_define_singleton_method(klass, "gcd_normal", gcd_normal, 2);
|
||||
rb_define_singleton_method(klass, "gcd_gmp", gcd_gmp, 2);
|
||||
|
||||
rb_define_singleton_method(klass, "raw", s_rational_raw, 2);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ io_handle(VALUE io)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
console_info(VALUE io)
|
||||
console_info(VALUE klass, VALUE io)
|
||||
{
|
||||
HANDLE h = io_handle(io);
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
@ -29,7 +29,7 @@ console_info(VALUE io)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
console_set_attribute(VALUE io, VALUE attr)
|
||||
console_set_attribute(VALUE klass, VALUE io, VALUE attr)
|
||||
{
|
||||
HANDLE h = io_handle(io);
|
||||
|
||||
|
@ -47,8 +47,8 @@ Init_attribute(VALUE m)
|
|||
"size_x", "size_y",
|
||||
"cur_x", "cur_y",
|
||||
"attr", NULL);
|
||||
rb_define_method(rb_cIO, "console_info", console_info, 0);
|
||||
rb_define_method(rb_cIO, "console_attribute", console_set_attribute, 1);
|
||||
rb_define_singleton_method(m, "console_info", console_info, 1);
|
||||
rb_define_singleton_method(m, "console_attribute", console_set_attribute, 2);
|
||||
|
||||
rb_define_const(m, "FOREGROUND_MASK", INT2FIX(FOREGROUND_MASK));
|
||||
rb_define_const(m, "FOREGROUND_BLUE", INT2FIX(FOREGROUND_BLUE));
|
||||
|
|
|
@ -3,6 +3,12 @@ require 'test/unit'
|
|||
require '-test-/array/resize'
|
||||
|
||||
class Test_Array < Test::Unit::TestCase
|
||||
using Module.new {
|
||||
refine(Array) {
|
||||
def __resize__(len) ::Bug::Array.__resize__(self, len); end
|
||||
}
|
||||
}
|
||||
|
||||
class TestResize < Test::Unit::TestCase
|
||||
def test_expand
|
||||
feature = '[ruby-dev:42912]'
|
||||
|
|
|
@ -5,24 +5,24 @@ require "-test-/bignum"
|
|||
class Test_Bignum < Test::Unit::TestCase
|
||||
class TestBig2str < Test::Unit::TestCase
|
||||
|
||||
SIZEOF_BDIGIT = Integer::SIZEOF_BDIGIT
|
||||
BITSPERDIG = Integer::BITSPERDIG
|
||||
SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
|
||||
BITSPERDIG = Bug::Bignum::BITSPERDIG
|
||||
BDIGMAX = (1 << BITSPERDIG) - 1
|
||||
|
||||
def test_big2str_generic
|
||||
x = 10**1000
|
||||
assert_equal("1" + "0" * 1000, x.big2str_generic(10))
|
||||
assert_equal("1" + "0" * 1000, Bug::Bignum.big2str_generic(x, 10))
|
||||
end
|
||||
|
||||
def test_big2str_poweroftwo
|
||||
e = BITSPERDIG*2
|
||||
x = 0b10**e
|
||||
assert_equal("1" + "0" * e, x.big2str_poweroftwo(2))
|
||||
assert_equal("1" + "0" * e, Bug::Bignum.big2str_poweroftwo(x, 2))
|
||||
end
|
||||
|
||||
def test_big2str_gmp
|
||||
x = 10**1000
|
||||
assert_equal("1" + "0" * 1000, x.big2str_gmp(10))
|
||||
assert_equal("1" + "0" * 1000, Bug::Bignum.big2str_gmp(x, 10))
|
||||
rescue NotImplementedError
|
||||
end
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ require "-test-/bignum"
|
|||
class Test_Bignum < Test::Unit::TestCase
|
||||
class TestDiv < Test::Unit::TestCase
|
||||
|
||||
SIZEOF_BDIGIT = Integer::SIZEOF_BDIGIT
|
||||
BITSPERDIG = Integer::BITSPERDIG
|
||||
SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
|
||||
BITSPERDIG = Bug::Bignum::BITSPERDIG
|
||||
BDIGMAX = (1 << BITSPERDIG) - 1
|
||||
|
||||
def test_divrem_normal
|
||||
|
@ -14,7 +14,7 @@ class Test_Bignum < Test::Unit::TestCase
|
|||
y = (1 << BITSPERDIG) | 1
|
||||
q = (1 << BITSPERDIG) | 1
|
||||
r = 2
|
||||
assert_equal([q, r], x.big_divrem_normal(y))
|
||||
assert_equal([q, r], Bug::Bignum.big_divrem_normal(x, y))
|
||||
end
|
||||
|
||||
def test_divrem_gmp
|
||||
|
@ -22,7 +22,7 @@ class Test_Bignum < Test::Unit::TestCase
|
|||
y = (1 << BITSPERDIG) | 1
|
||||
q = (1 << BITSPERDIG) | 1
|
||||
r = 2
|
||||
assert_equal([q, r], x.big_divrem_gmp(y))
|
||||
assert_equal([q, r], Bug::Bignum.big_divrem_gmp(x, y))
|
||||
rescue NotImplementedError
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,132 +5,132 @@ require "-test-/bignum"
|
|||
class Test_Bignum < Test::Unit::TestCase
|
||||
class TestMul < Test::Unit::TestCase
|
||||
|
||||
SIZEOF_BDIGIT = Integer::SIZEOF_BDIGIT
|
||||
BITSPERDIG = Integer::BITSPERDIG
|
||||
SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
|
||||
BITSPERDIG = Bug::Bignum::BITSPERDIG
|
||||
BDIGMAX = (1 << BITSPERDIG) - 1
|
||||
|
||||
def test_mul_normal
|
||||
x = (1 << BITSPERDIG) | 1
|
||||
y = (1 << BITSPERDIG) | 1
|
||||
z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
|
||||
assert_equal(z, x.big_mul_normal(y))
|
||||
assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
|
||||
end
|
||||
|
||||
def test_mul_normal_zero_in_x
|
||||
x = (1 << (2*BITSPERDIG)) | 1
|
||||
y = (1 << BITSPERDIG) | 1
|
||||
z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1
|
||||
assert_equal(z, x.big_mul_normal(y))
|
||||
assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
|
||||
end
|
||||
|
||||
def test_mul_normal_zero_in_y
|
||||
x = (1 << BITSPERDIG) | 1
|
||||
y = (1 << (2*BITSPERDIG)) | 1
|
||||
z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1
|
||||
assert_equal(z, x.big_mul_normal(y))
|
||||
assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
|
||||
end
|
||||
|
||||
def test_mul_normal_max_max
|
||||
x = (1 << (2*BITSPERDIG)) - 1
|
||||
y = (1 << (2*BITSPERDIG)) - 1
|
||||
z = (1 << (4*BITSPERDIG)) - (1 << (2*BITSPERDIG+1)) + 1
|
||||
assert_equal(z, x.big_mul_normal(y))
|
||||
assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
|
||||
end
|
||||
|
||||
def test_sq_fast
|
||||
x = (1 << BITSPERDIG) | 1
|
||||
z = (1 << 2*BITSPERDIG) | (2 << BITSPERDIG) | 1
|
||||
assert_equal(z, x.big_sq_fast)
|
||||
assert_equal(z, Bug::Bignum.big_sq_fast(x))
|
||||
end
|
||||
|
||||
def test_sq_fast_max2
|
||||
x = (BDIGMAX << BITSPERDIG) | BDIGMAX
|
||||
assert_equal(x.big_mul_normal(x), x.big_sq_fast)
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, x), Bug::Bignum.big_sq_fast(x))
|
||||
end
|
||||
|
||||
def test_sq_fast_zero_in_middle
|
||||
x = (BDIGMAX << 2*BITSPERDIG) | BDIGMAX
|
||||
assert_equal(x.big_mul_normal(x), x.big_sq_fast)
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, x), Bug::Bignum.big_sq_fast(x))
|
||||
end
|
||||
|
||||
def test_mul_balance
|
||||
x = (1 << BITSPERDIG) | 1
|
||||
y = (1 << BITSPERDIG) | 1
|
||||
z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
|
||||
assert_equal(z, x.big_mul_balance(y))
|
||||
assert_equal(z, Bug::Bignum.big_mul_balance(x, y))
|
||||
end
|
||||
|
||||
def test_mul_balance_2x16
|
||||
x = (1 << Integer::BITSPERDIG) | 1
|
||||
y = (1 << Integer::BITSPERDIG*16) | 1
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_balance(y))
|
||||
x = (1 << BITSPERDIG) | 1
|
||||
y = (1 << BITSPERDIG*16) | 1
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_balance(x, y))
|
||||
end
|
||||
|
||||
def test_mul_balance_2x17
|
||||
x = (1 << Integer::BITSPERDIG) | 1
|
||||
y = (1 << Integer::BITSPERDIG*17) | 1
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_balance(y))
|
||||
x = (1 << BITSPERDIG) | 1
|
||||
y = (1 << BITSPERDIG*17) | 1
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_balance(x, y))
|
||||
end
|
||||
|
||||
def test_mul_karatsuba
|
||||
x = (1 << BITSPERDIG) | 1
|
||||
y = (1 << BITSPERDIG) | 1
|
||||
z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
|
||||
assert_equal(z, x.big_mul_karatsuba(y))
|
||||
assert_equal(z, Bug::Bignum.big_mul_karatsuba(x, y))
|
||||
end
|
||||
|
||||
def test_mul_karatsuba_odd_y
|
||||
x = (1 << BITSPERDIG) | 1
|
||||
y = (1 << (2*BITSPERDIG)) | 1
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y))
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
|
||||
end
|
||||
|
||||
def test_mul_karatsuba_odd_xy
|
||||
x = (1 << (2*BITSPERDIG)) | 1
|
||||
y = (1 << (2*BITSPERDIG)) | 1
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y))
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
|
||||
end
|
||||
|
||||
def test_mul_karatsuba_x1_gt_x0
|
||||
x = (2 << BITSPERDIG) | 1
|
||||
y = (1 << BITSPERDIG) | 2
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y))
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
|
||||
end
|
||||
|
||||
def test_mul_karatsuba_y1_gt_y0
|
||||
x = (1 << BITSPERDIG) | 2
|
||||
y = (2 << BITSPERDIG) | 1
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y))
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
|
||||
end
|
||||
|
||||
def test_mul_karatsuba_x1_gt_x0_and_y1_gt_y0
|
||||
x = (2 << BITSPERDIG) | 1
|
||||
y = (2 << BITSPERDIG) | 1
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y))
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
|
||||
end
|
||||
|
||||
def test_mul_karatsuba_carry2
|
||||
x = (1 << BITSPERDIG) | BDIGMAX
|
||||
y = (1 << BITSPERDIG) | BDIGMAX
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y))
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
|
||||
end
|
||||
|
||||
def test_mul_karatsuba_borrow
|
||||
x = (BDIGMAX << BITSPERDIG) | 1
|
||||
y = (BDIGMAX << BITSPERDIG) | 1
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y))
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
|
||||
end
|
||||
|
||||
def test_mul_toom3
|
||||
x = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
|
||||
y = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_toom3(y))
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_toom3(x, y))
|
||||
end
|
||||
|
||||
def test_mul_gmp
|
||||
x = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
|
||||
y = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
|
||||
assert_equal(x.big_mul_normal(y), x.big_mul_gmp(y))
|
||||
assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_gmp(x, y))
|
||||
rescue NotImplementedError
|
||||
end
|
||||
|
||||
|
|
|
@ -7,102 +7,102 @@ require "-test-/bignum"
|
|||
class Test_Bignum < Test::Unit::TestCase
|
||||
class TestPack < Test::Unit::TestCase
|
||||
|
||||
MSWORD_FIRST = Integer::INTEGER_PACK_MSWORD_FIRST
|
||||
LSWORD_FIRST = Integer::INTEGER_PACK_LSWORD_FIRST
|
||||
MSBYTE_FIRST = Integer::INTEGER_PACK_MSBYTE_FIRST
|
||||
LSBYTE_FIRST = Integer::INTEGER_PACK_LSBYTE_FIRST
|
||||
NATIVE_BYTE_ORDER = Integer::INTEGER_PACK_NATIVE_BYTE_ORDER
|
||||
TWOCOMP = Integer::INTEGER_PACK_2COMP
|
||||
LITTLE_ENDIAN = Integer::INTEGER_PACK_LITTLE_ENDIAN
|
||||
BIG_ENDIAN = Integer::INTEGER_PACK_BIG_ENDIAN
|
||||
NEGATIVE = Integer::INTEGER_PACK_NEGATIVE
|
||||
GENERIC = Integer::INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION
|
||||
MSWORD_FIRST = Bug::Bignum::INTEGER_PACK_MSWORD_FIRST
|
||||
LSWORD_FIRST = Bug::Bignum::INTEGER_PACK_LSWORD_FIRST
|
||||
MSBYTE_FIRST = Bug::Bignum::INTEGER_PACK_MSBYTE_FIRST
|
||||
LSBYTE_FIRST = Bug::Bignum::INTEGER_PACK_LSBYTE_FIRST
|
||||
NATIVE_BYTE_ORDER = Bug::Bignum::INTEGER_PACK_NATIVE_BYTE_ORDER
|
||||
TWOCOMP = Bug::Bignum::INTEGER_PACK_2COMP
|
||||
LITTLE_ENDIAN = Bug::Bignum::INTEGER_PACK_LITTLE_ENDIAN
|
||||
BIG_ENDIAN = Bug::Bignum::INTEGER_PACK_BIG_ENDIAN
|
||||
NEGATIVE = Bug::Bignum::INTEGER_PACK_NEGATIVE
|
||||
GENERIC = Bug::Bignum::INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION
|
||||
|
||||
def test_pack_zero
|
||||
assert_equal([0, ""], 0.test_pack(0, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, BIG_ENDIAN))
|
||||
end
|
||||
|
||||
def test_pack_argument_check
|
||||
assert_raise(ArgumentError) { 0.test_pack_raw("", 2, 1, 0, MSBYTE_FIRST) }
|
||||
assert_raise(ArgumentError) { 0.test_pack_raw("", 0, 1, 0, MSWORD_FIRST) }
|
||||
assert_raise(ArgumentError) { 0.test_pack_raw("", 0, 0, 0, BIG_ENDIAN) }
|
||||
assert_raise(ArgumentError) { 0.test_pack_raw("", 0, 1, 8, BIG_ENDIAN) }
|
||||
assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 2, 1, 0, MSBYTE_FIRST) }
|
||||
assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 1, 0, MSWORD_FIRST) }
|
||||
assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 0, 0, BIG_ENDIAN) }
|
||||
assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 1, 8, BIG_ENDIAN) }
|
||||
|
||||
# assume sizeof(ssize_t) == sizeof(intptr_t)
|
||||
assert_raise(ArgumentError) { 0.test_pack_raw("", 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
|
||||
assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
|
||||
end
|
||||
|
||||
def test_pack_wordsize
|
||||
assert_equal([1, "\x01"], 1.test_pack(1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([1, "\x00\x01"], 1.test_pack(1, 2, 0, BIG_ENDIAN))
|
||||
assert_equal([1, "\x00\x00\x01"], 1.test_pack(1, 3, 0, BIG_ENDIAN))
|
||||
assert_equal([1, "\x01"], 1.test_pack(1, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([1, "\x01\x00"], 1.test_pack(1, 2, 0, LITTLE_ENDIAN))
|
||||
assert_equal([1, "\x01\x00\x00"], 1.test_pack(1, 3, 0, LITTLE_ENDIAN))
|
||||
assert_equal([1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([1, "\x00\x01"], Bug::Bignum.test_pack(1, 1, 2, 0, BIG_ENDIAN))
|
||||
assert_equal([1, "\x00\x00\x01"], Bug::Bignum.test_pack(1, 1, 3, 0, BIG_ENDIAN))
|
||||
assert_equal([1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([1, "\x01\x00"], Bug::Bignum.test_pack(1, 1, 2, 0, LITTLE_ENDIAN))
|
||||
assert_equal([1, "\x01\x00\x00"], Bug::Bignum.test_pack(1, 1, 3, 0, LITTLE_ENDIAN))
|
||||
end
|
||||
|
||||
def test_pack_fixed_buffer
|
||||
assert_equal([0, "\x00\x00"], 0.test_pack(2, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([1, "\x00\x01"], 0x01.test_pack(2, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([1, "\x02\x01"], 0x0201.test_pack(2, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([2, "\x02\x01"], 0x030201.test_pack(2, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([2, "\x02\x01"], 0x04030201.test_pack(2, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([0, "\x00\x00"], 0.test_pack(2, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([1, "\x01\x00"], 0x01.test_pack(2, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([1, "\x01\x02"], 0x0201.test_pack(2, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([2, "\x01\x02"], 0x030201.test_pack(2, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([2, "\x01\x02"], 0x04030201.test_pack(2, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([0, "\x00\x00"], Bug::Bignum.test_pack(0, 2, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([1, "\x00\x01"], Bug::Bignum.test_pack(0x01, 2, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([1, "\x02\x01"], Bug::Bignum.test_pack(0x0201, 2, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([2, "\x02\x01"], Bug::Bignum.test_pack(0x030201, 2, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([2, "\x02\x01"], Bug::Bignum.test_pack(0x04030201, 2, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([0, "\x00\x00"], Bug::Bignum.test_pack(0, 2, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([1, "\x01\x00"], Bug::Bignum.test_pack(0x01, 2, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([1, "\x01\x02"], Bug::Bignum.test_pack(0x0201, 2, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([2, "\x01\x02"], Bug::Bignum.test_pack(0x030201, 2, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal([2, "\x01\x02"], Bug::Bignum.test_pack(0x04030201, 2, 1, 0, LITTLE_ENDIAN))
|
||||
end
|
||||
|
||||
def test_pack_wordorder_and_endian
|
||||
assert_equal([1, "\x12\x34\x56\x78"], 0x12345678.test_pack(2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
|
||||
assert_equal([1, "\x34\x12\x78\x56"], 0x12345678.test_pack(2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
|
||||
assert_equal([1, "\x56\x78\x12\x34"], 0x12345678.test_pack(2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
|
||||
assert_equal([1, "\x78\x56\x34\x12"], 0x12345678.test_pack(2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
|
||||
assert_equal([1, "\x12\x34\x56\x78"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
|
||||
assert_equal([1, "\x34\x12\x78\x56"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
|
||||
assert_equal([1, "\x56\x78\x12\x34"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
|
||||
assert_equal([1, "\x78\x56\x34\x12"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
|
||||
end
|
||||
|
||||
def test_pack_native_endian
|
||||
assert_equal([1, [0x1234].pack("S!")], 0x1234.test_pack(1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
|
||||
assert_equal([1, [0x1234].pack("S!")], Bug::Bignum.test_pack(0x1234, 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
|
||||
end
|
||||
|
||||
def test_pack_nail
|
||||
assert_equal([1, "\x01\x00\x00\x00\x01\x01"], 0b100011.test_pack(6, 1, 7, BIG_ENDIAN))
|
||||
assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08"], 0x12345678.test_pack(8, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78"], 0x12345678.test_pack(4, 2, 8, BIG_ENDIAN))
|
||||
assert_equal([1, "\x01\x00\x00\x00\x01\x01"], Bug::Bignum.test_pack(0b100011, 6, 1, 7, BIG_ENDIAN))
|
||||
assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08"], Bug::Bignum.test_pack(0x12345678, 8, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78"], Bug::Bignum.test_pack(0x12345678, 4, 2, 8, BIG_ENDIAN))
|
||||
end
|
||||
|
||||
def test_pack_overflow
|
||||
assert_equal([-2, "\x1"], (-0x11).test_pack(1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x0"], (-0x10).test_pack(1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([-1, "\xF"], (-0x0F).test_pack(1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([+1, "\xF"], (+0x0F).test_pack(1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x0"], (+0x10).test_pack(1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x1"], (+0x11).test_pack(1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x1"], Bug::Bignum.test_pack((-0x11), 1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x0"], Bug::Bignum.test_pack((-0x10), 1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([-1, "\xF"], Bug::Bignum.test_pack((-0x0F), 1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([+1, "\xF"], Bug::Bignum.test_pack((+0x0F), 1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x0"], Bug::Bignum.test_pack((+0x10), 1, 1, 4, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x1"], Bug::Bignum.test_pack((+0x11), 1, 1, 4, BIG_ENDIAN))
|
||||
|
||||
assert_equal([-2, "\x01"], (-0x101).test_pack(1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x00"], (-0x100).test_pack(1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([-1, "\xFF"], (-0x0FF).test_pack(1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF"], (+0x0FF).test_pack(1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"], (+0x100).test_pack(1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x01"], (+0x101).test_pack(1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x01"], Bug::Bignum.test_pack((-0x101), 1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x00"], Bug::Bignum.test_pack((-0x100), 1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([-1, "\xFF"], Bug::Bignum.test_pack((-0x0FF), 1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF"], Bug::Bignum.test_pack((+0x0FF), 1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"], Bug::Bignum.test_pack((+0x100), 1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x01"], Bug::Bignum.test_pack((+0x101), 1, 1, 0, BIG_ENDIAN))
|
||||
|
||||
assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x01"], (-0x10000000000000001).test_pack(2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x00"], (-0x10000000000000000).test_pack(2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([-1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], (-0x0FFFFFFFFFFFFFFFF).test_pack(2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], (+0x0FFFFFFFFFFFFFFFF).test_pack(2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], (+0x10000000000000000).test_pack(2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], (+0x10000000000000001).test_pack(2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((-0x10000000000000001), 2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((-0x10000000000000000), 2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([-1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((-0x0FFFFFFFFFFFFFFFF), 2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((+0x0FFFFFFFFFFFFFFFF), 2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((+0x10000000000000000), 2, 4, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((+0x10000000000000001), 2, 4, 0, BIG_ENDIAN))
|
||||
|
||||
1.upto(16) {|wordsize|
|
||||
1.upto(20) {|numwords|
|
||||
w = numwords*wordsize
|
||||
n = 256**w
|
||||
assert_equal([-2, "\x00"*(w-1)+"\x01"], (-n-1).test_pack(numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x00"*w], (-n ).test_pack(numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([-1, "\xFF"*w], (-n+1).test_pack(numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF"*w], (+n-1).test_pack(numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"*w], (+n ).test_pack(numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"*(w-1)+"\x01"], (+n+1).test_pack(numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([-2, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([-1, "\xFF"*w], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, BIG_ENDIAN))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,19 +110,19 @@ class Test_Bignum < Test::Unit::TestCase
|
|||
1.upto(20) {|numwords|
|
||||
w = numwords*wordsize
|
||||
n = 256**w
|
||||
assert_equal([-2, "\x01"+"\x00"*(w-1)], (-n-1).test_pack(numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([-2, "\x00"*w], (-n ).test_pack(numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([-1, "\xFF"*w], (-n+1).test_pack(numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([+1, "\xFF"*w], (+n-1).test_pack(numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([+2, "\x00"*w], (+n ).test_pack(numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([+2, "\x01"+"\x00"*(w-1)], (+n+1).test_pack(numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([-2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([-2, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([-1, "\xFF"*w], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
assert_equal([+2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, LITTLE_ENDIAN))
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_pack_sign
|
||||
assert_equal([-1, "\x01"], (-1).test_pack(1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10"], (-0x8070605040302010).test_pack(8, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([-1, "\x01"], Bug::Bignum.test_pack((-1), 1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10"], Bug::Bignum.test_pack((-0x8070605040302010), 8, 1, 0, BIG_ENDIAN))
|
||||
end
|
||||
|
||||
def test_pack_orders
|
||||
|
@ -135,8 +135,8 @@ class Test_Bignum < Test::Unit::TestCase
|
|||
0.upto(w) {|i|
|
||||
n |= ((i+1) % 256) << (i*8)
|
||||
}
|
||||
assert_equal(n.test_pack(numwords, wordsize, 0, word_order|byte_order|GENERIC),
|
||||
n.test_pack(numwords, wordsize, 0, word_order|byte_order),
|
||||
assert_equal(Bug::Bignum.test_pack(n, numwords, wordsize, 0, word_order|byte_order|GENERIC),
|
||||
Bug::Bignum.test_pack(n, numwords, wordsize, 0, word_order|byte_order),
|
||||
"#{'%#x' % n}.test_pack(#{numwords}, #{wordsize}, 0, #{'%#x' % (word_order|byte_order)})")
|
||||
}
|
||||
}
|
||||
|
@ -145,58 +145,58 @@ class Test_Bignum < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_pack2comp_zero
|
||||
assert_equal([0, ""], 0.test_pack(0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
end
|
||||
|
||||
def test_pack2comp_emptybuf
|
||||
assert_equal([-2, ""], (-3).test_pack(0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-2, ""], (-2).test_pack(0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, ""], (-1).test_pack(0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([ 0, ""], 0.test_pack(0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, ""], 1.test_pack(0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, ""], 2.test_pack(0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-2, ""], Bug::Bignum.test_pack((-3), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-2, ""], Bug::Bignum.test_pack((-2), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, ""], Bug::Bignum.test_pack((-1), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([ 0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, ""], Bug::Bignum.test_pack(1, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, ""], Bug::Bignum.test_pack(2, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
end
|
||||
|
||||
def test_pack2comp_nearly_zero
|
||||
assert_equal([-1, "\xFE"], (-2).test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\xFF"], (-1).test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([ 0, "\x00"], 0.test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\x01"], 1.test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\x02"], 2.test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\xFE"], Bug::Bignum.test_pack((-2), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\xFF"], Bug::Bignum.test_pack((-1), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([ 0, "\x00"], Bug::Bignum.test_pack(0, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\x02"], Bug::Bignum.test_pack(2, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
end
|
||||
|
||||
def test_pack2comp_overflow
|
||||
assert_equal([-2, "\xF"], (-0x11).test_pack(1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x0"], (-0x10).test_pack(1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x1"], (-0x0F).test_pack(1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\xF"], (+0x0F).test_pack(1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x0"], (+0x10).test_pack(1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x1"], (+0x11).test_pack(1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-2, "\xF"], Bug::Bignum.test_pack((-0x11), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x0"], Bug::Bignum.test_pack((-0x10), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x1"], Bug::Bignum.test_pack((-0x0F), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\xF"], Bug::Bignum.test_pack((+0x0F), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x0"], Bug::Bignum.test_pack((+0x10), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x1"], Bug::Bignum.test_pack((+0x11), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
|
||||
|
||||
assert_equal([-2, "\xFF"], (-0x101).test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x00"], (-0x100).test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x01"], (-0x0FF).test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF"], (+0x0FF).test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"], (+0x100).test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x01"], (+0x101).test_pack(1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-2, "\xFF"], Bug::Bignum.test_pack((-0x101), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x00"], Bug::Bignum.test_pack((-0x100), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x01"], Bug::Bignum.test_pack((-0x0FF), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF"], Bug::Bignum.test_pack((+0x0FF), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"], Bug::Bignum.test_pack((+0x100), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x01"], Bug::Bignum.test_pack((+0x101), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
|
||||
assert_equal([-2, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], (-0x10000000000000001).test_pack(2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x00"], (-0x10000000000000000).test_pack(2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x01"], (-0x0FFFFFFFFFFFFFFFF).test_pack(2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], (+0x0FFFFFFFFFFFFFFFF).test_pack(2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], (+0x10000000000000000).test_pack(2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], (+0x10000000000000001).test_pack(2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-2, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((-0x10000000000000001), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((-0x10000000000000000), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((-0x0FFFFFFFFFFFFFFFF), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((+0x0FFFFFFFFFFFFFFFF), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((+0x10000000000000000), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((+0x10000000000000001), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
|
||||
|
||||
1.upto(16) {|wordsize|
|
||||
1.upto(20) {|numwords|
|
||||
w = numwords*wordsize
|
||||
n = 256**w
|
||||
assert_equal([-2, "\xFF"*w ], (-n-1).test_pack(numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x00"*w], (-n ).test_pack(numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x00"*(w-1)+"\x01"], (-n+1).test_pack(numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF"*w], (+n-1).test_pack(numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"*w], (+n ).test_pack(numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"*(w-1)+"\x01"], (+n+1).test_pack(numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-2, "\xFF"*w ], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([-1, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal([+2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,12 +204,12 @@ class Test_Bignum < Test::Unit::TestCase
|
|||
1.upto(20) {|numwords|
|
||||
w = numwords*wordsize
|
||||
n = 256**w
|
||||
assert_equal([-2, "\xFF"*w ], (-n-1).test_pack(numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([-1, "\x00"*w], (-n ).test_pack(numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([-1, "\x01"+"\x00"*(w-1)], (-n+1).test_pack(numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([+1, "\xFF"*w], (+n-1).test_pack(numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([+2, "\x00"*w], (+n ).test_pack(numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([+2, "\x01"+"\x00"*(w-1)], (+n+1).test_pack(numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([-2, "\xFF"*w ], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([-1, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([-1, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
assert_equal([+2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,71 +217,71 @@ class Test_Bignum < Test::Unit::TestCase
|
|||
w = wordsize
|
||||
b = 8*wordsize-1
|
||||
n = 2**b
|
||||
assert_equal([-2, "\x7F"+"\xFF"*(w-2)+"\xFF"], (-n-1).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], (-n ).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x01"], (-n+1).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([+1, "\x7F"+"\xFF"*(w-2)+"\xFF"], (+n-1).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], (+n ).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x01"], (+n+1).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([-2, "\x7F"+"\xFF"*(w-2)+"\xFF"], Bug::Bignum.test_pack((-n-1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n ), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x01"], Bug::Bignum.test_pack((-n+1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([+1, "\x7F"+"\xFF"*(w-2)+"\xFF"], Bug::Bignum.test_pack((+n-1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n ), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x01"], Bug::Bignum.test_pack((+n+1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
|
||||
}
|
||||
|
||||
2.upto(16) {|wordsize|
|
||||
w = wordsize
|
||||
b = 8*wordsize-1
|
||||
n = 2**b
|
||||
assert_equal([-2, "\xFF"+"\xFF"*(w-2)+"\x7F"], (-n-1).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], (-n ).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([-1, "\x01"+"\x00"*(w-2)+"\x00"], (-n+1).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([+1, "\xFF"+"\xFF"*(w-2)+"\x7F"], (+n-1).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], (+n ).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([+2, "\x01"+"\x00"*(w-2)+"\x00"], (+n+1).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([-2, "\xFF"+"\xFF"*(w-2)+"\x7F"], Bug::Bignum.test_pack((-n-1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n ), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([-1, "\x01"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n+1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([+1, "\xFF"+"\xFF"*(w-2)+"\x7F"], Bug::Bignum.test_pack((+n-1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n ), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
assert_equal([+2, "\x01"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n+1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
def test_unpack_zero
|
||||
assert_equal(0, Integer.test_unpack("", 0, 1, 0, BIG_ENDIAN))
|
||||
assert_equal(0, Bug::Bignum.test_unpack("", 0, 1, 0, BIG_ENDIAN))
|
||||
end
|
||||
|
||||
def test_unpack_argument_check
|
||||
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) }
|
||||
assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 2, 1, 0, MSBYTE_FIRST) }
|
||||
assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1, 0, MSWORD_FIRST) }
|
||||
assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 0, 0, BIG_ENDIAN) }
|
||||
assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1, 8, BIG_ENDIAN) }
|
||||
|
||||
# assume sizeof(ssize_t) == sizeof(intptr_t)
|
||||
assert_raise(ArgumentError) { Integer.test_unpack("x", 1, 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
|
||||
assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
|
||||
end
|
||||
|
||||
def test_unpack_wordsize
|
||||
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))
|
||||
assert_equal(1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN))
|
||||
assert_equal(1, Bug::Bignum.test_unpack("\x00\x01", 1, 2, 0, BIG_ENDIAN))
|
||||
assert_equal(1, Bug::Bignum.test_unpack("\x00\x00\x01", 1, 3, 0, BIG_ENDIAN))
|
||||
assert_equal(1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, LITTLE_ENDIAN))
|
||||
assert_equal(1, Bug::Bignum.test_unpack("\x01\x00", 1, 2, 0, LITTLE_ENDIAN))
|
||||
assert_equal(1, Bug::Bignum.test_unpack("\x01\x00\x00", 1, 3, 0, LITTLE_ENDIAN))
|
||||
end
|
||||
|
||||
def test_unpack_wordorder_and_endian
|
||||
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))
|
||||
assert_equal(0x01020304, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
|
||||
assert_equal(0x02010403, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
|
||||
assert_equal(0x03040102, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
|
||||
assert_equal(0x04030201, Bug::Bignum.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("\x12\x34", 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
|
||||
assert_equal("\x12\x34".unpack("S!")[0], Bug::Bignum.test_unpack("\x12\x34", 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
|
||||
end
|
||||
|
||||
def test_unpack_nail
|
||||
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))
|
||||
assert_equal(0b100011, Bug::Bignum.test_unpack("\x01\x00\x00\x00\x01\x01", 6, 1, 7, BIG_ENDIAN))
|
||||
assert_equal(0x12345678, Bug::Bignum.test_unpack("\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 4, BIG_ENDIAN))
|
||||
assert_equal(0x12345678, Bug::Bignum.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("\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))
|
||||
assert_equal(-1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal(-0x8070605040302010, Bug::Bignum.test_unpack("\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 0, BIG_ENDIAN|NEGATIVE))
|
||||
end
|
||||
|
||||
def test_unpack_orders
|
||||
|
@ -296,9 +296,9 @@ class Test_Bignum < Test::Unit::TestCase
|
|||
}
|
||||
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})")
|
||||
assert_equal(Bug::Bignum.test_unpack(str, numwords, wordsize, 0, flags|GENERIC),
|
||||
Bug::Bignum.test_unpack(str, numwords, wordsize, 0, flags),
|
||||
"Bug::Bignum.test_unpack(#{str.dump}, #{numwords}, #{wordsize}, 0, #{'%#x' % flags})")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -306,94 +306,94 @@ class Test_Bignum < Test::Unit::TestCase
|
|||
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))
|
||||
assert_equal( -1, Integer.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal( 0, Integer.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal( 1, Integer.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal( 2, Integer.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal( 127, Integer.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-128, Bug::Bignum.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal( -2, Bug::Bignum.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal( -1, Bug::Bignum.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal( 0, Bug::Bignum.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal( 1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal( 2, Bug::Bignum.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal( 127, Bug::Bignum.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
end
|
||||
|
||||
def test_unpack2comp_sequence_of_ff
|
||||
assert_equal(-1, Integer.test_unpack("\xFF"*2, 2, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Integer.test_unpack("\xFF"*3, 3, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Integer.test_unpack("\xFF"*4, 4, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Integer.test_unpack("\xFF"*5, 5, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Integer.test_unpack("\xFF"*6, 6, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Integer.test_unpack("\xFF"*7, 7, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Integer.test_unpack("\xFF"*8, 8, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Integer.test_unpack("\xFF"*9, 9, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*2, 2, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*3, 3, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*4, 4, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*5, 5, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*6, 6, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*7, 7, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*8, 8, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*9, 9, 1, 0, TWOCOMP|BIG_ENDIAN))
|
||||
end
|
||||
|
||||
def test_unpack2comp_negative_single_byte
|
||||
assert_equal(-256, Integer.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal(-255, Integer.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal(-254, Integer.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal(-129, Integer.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal(-128, Integer.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal( -2, Integer.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal( -1, Integer.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal(-256, Bug::Bignum.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal(-255, Bug::Bignum.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal(-254, Bug::Bignum.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal(-129, Bug::Bignum.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal(-128, Bug::Bignum.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal( -2, Bug::Bignum.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
assert_equal( -1, Bug::Bignum.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
|
||||
end
|
||||
|
||||
def test_unpack2comp_negative_zero
|
||||
0.upto(100) {|n|
|
||||
str = "\x00"*n
|
||||
flags = TWOCOMP|BIG_ENDIAN|NEGATIVE
|
||||
assert_equal(-(256**n), Integer.test_unpack(str, n, 1, 0, flags))
|
||||
assert_equal(-(256**n), Bug::Bignum.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})")
|
||||
assert_equal(-(256**n), Bug::Bignum.test_unpack(str, n, 1, 0, flags),
|
||||
"Bug::Bignum.test_unpack(#{str.dump}, #{n}, 1, 0, #{'%#x' % flags})")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_numbits_2comp
|
||||
assert_equal(4, -9.test_numbits_2comp_without_sign)
|
||||
assert_equal(3, -8.test_numbits_2comp_without_sign)
|
||||
assert_equal(3, -7.test_numbits_2comp_without_sign)
|
||||
assert_equal(3, -6.test_numbits_2comp_without_sign)
|
||||
assert_equal(3, -5.test_numbits_2comp_without_sign)
|
||||
assert_equal(2, -4.test_numbits_2comp_without_sign)
|
||||
assert_equal(2, -3.test_numbits_2comp_without_sign)
|
||||
assert_equal(1, -2.test_numbits_2comp_without_sign)
|
||||
assert_equal(0, -1.test_numbits_2comp_without_sign)
|
||||
assert_equal(0, 0.test_numbits_2comp_without_sign)
|
||||
assert_equal(1, 1.test_numbits_2comp_without_sign)
|
||||
assert_equal(2, 2.test_numbits_2comp_without_sign)
|
||||
assert_equal(2, 3.test_numbits_2comp_without_sign)
|
||||
assert_equal(3, 4.test_numbits_2comp_without_sign)
|
||||
assert_equal(3, 5.test_numbits_2comp_without_sign)
|
||||
assert_equal(3, 6.test_numbits_2comp_without_sign)
|
||||
assert_equal(3, 7.test_numbits_2comp_without_sign)
|
||||
assert_equal(4, 8.test_numbits_2comp_without_sign)
|
||||
assert_equal(4, 9.test_numbits_2comp_without_sign)
|
||||
assert_equal(4, Bug::Bignum.test_numbits_2comp_without_sign(-9))
|
||||
assert_equal(3, Bug::Bignum.test_numbits_2comp_without_sign(-8))
|
||||
assert_equal(3, Bug::Bignum.test_numbits_2comp_without_sign(-7))
|
||||
assert_equal(3, Bug::Bignum.test_numbits_2comp_without_sign(-6))
|
||||
assert_equal(3, Bug::Bignum.test_numbits_2comp_without_sign(-5))
|
||||
assert_equal(2, Bug::Bignum.test_numbits_2comp_without_sign(-4))
|
||||
assert_equal(2, Bug::Bignum.test_numbits_2comp_without_sign(-3))
|
||||
assert_equal(1, Bug::Bignum.test_numbits_2comp_without_sign(-2))
|
||||
assert_equal(0, Bug::Bignum.test_numbits_2comp_without_sign(-1))
|
||||
assert_equal(0, Bug::Bignum.test_numbits_2comp_without_sign(0))
|
||||
assert_equal(1, Bug::Bignum.test_numbits_2comp_without_sign(1))
|
||||
assert_equal(2, Bug::Bignum.test_numbits_2comp_without_sign(2))
|
||||
assert_equal(2, Bug::Bignum.test_numbits_2comp_without_sign(3))
|
||||
assert_equal(3, Bug::Bignum.test_numbits_2comp_without_sign(4))
|
||||
assert_equal(3, Bug::Bignum.test_numbits_2comp_without_sign(5))
|
||||
assert_equal(3, Bug::Bignum.test_numbits_2comp_without_sign(6))
|
||||
assert_equal(3, Bug::Bignum.test_numbits_2comp_without_sign(7))
|
||||
assert_equal(4, Bug::Bignum.test_numbits_2comp_without_sign(8))
|
||||
assert_equal(4, Bug::Bignum.test_numbits_2comp_without_sign(9))
|
||||
end
|
||||
|
||||
def test_numbytes_2comp
|
||||
assert_equal(6, -0x8000000001.test_numbytes_2comp_with_sign)
|
||||
assert_equal(5, -0x8000000000.test_numbytes_2comp_with_sign)
|
||||
assert_equal(5, -0x80000001.test_numbytes_2comp_with_sign)
|
||||
assert_equal(4, -0x80000000.test_numbytes_2comp_with_sign)
|
||||
assert_equal(4, -0x800001.test_numbytes_2comp_with_sign)
|
||||
assert_equal(3, -0x800000.test_numbytes_2comp_with_sign)
|
||||
assert_equal(3, -0x8001.test_numbytes_2comp_with_sign)
|
||||
assert_equal(2, -0x8000.test_numbytes_2comp_with_sign)
|
||||
assert_equal(2, -0x81.test_numbytes_2comp_with_sign)
|
||||
assert_equal(1, -0x80.test_numbytes_2comp_with_sign)
|
||||
assert_equal(1, -1.test_numbytes_2comp_with_sign)
|
||||
assert_equal(1, 0.test_numbytes_2comp_with_sign)
|
||||
assert_equal(1, 1.test_numbytes_2comp_with_sign)
|
||||
assert_equal(1, 0x7f.test_numbytes_2comp_with_sign)
|
||||
assert_equal(2, 0x80.test_numbytes_2comp_with_sign)
|
||||
assert_equal(2, 0x7fff.test_numbytes_2comp_with_sign)
|
||||
assert_equal(3, 0x8000.test_numbytes_2comp_with_sign)
|
||||
assert_equal(3, 0x7fffff.test_numbytes_2comp_with_sign)
|
||||
assert_equal(4, 0x800000.test_numbytes_2comp_with_sign)
|
||||
assert_equal(4, 0x7fffffff.test_numbytes_2comp_with_sign)
|
||||
assert_equal(5, 0x80000000.test_numbytes_2comp_with_sign)
|
||||
assert_equal(5, 0x7fffffffff.test_numbytes_2comp_with_sign)
|
||||
assert_equal(6, 0x8000000000.test_numbytes_2comp_with_sign)
|
||||
assert_equal(6, Bug::Bignum.test_numbytes_2comp_with_sign(-0x8000000001))
|
||||
assert_equal(5, Bug::Bignum.test_numbytes_2comp_with_sign(-0x8000000000))
|
||||
assert_equal(5, Bug::Bignum.test_numbytes_2comp_with_sign(-0x80000001))
|
||||
assert_equal(4, Bug::Bignum.test_numbytes_2comp_with_sign(-0x80000000))
|
||||
assert_equal(4, Bug::Bignum.test_numbytes_2comp_with_sign(-0x800001))
|
||||
assert_equal(3, Bug::Bignum.test_numbytes_2comp_with_sign(-0x800000))
|
||||
assert_equal(3, Bug::Bignum.test_numbytes_2comp_with_sign(-0x8001))
|
||||
assert_equal(2, Bug::Bignum.test_numbytes_2comp_with_sign(-0x8000))
|
||||
assert_equal(2, Bug::Bignum.test_numbytes_2comp_with_sign(-0x81))
|
||||
assert_equal(1, Bug::Bignum.test_numbytes_2comp_with_sign(-0x80))
|
||||
assert_equal(1, Bug::Bignum.test_numbytes_2comp_with_sign(-1))
|
||||
assert_equal(1, Bug::Bignum.test_numbytes_2comp_with_sign(0))
|
||||
assert_equal(1, Bug::Bignum.test_numbytes_2comp_with_sign(1))
|
||||
assert_equal(1, Bug::Bignum.test_numbytes_2comp_with_sign(0x7f))
|
||||
assert_equal(2, Bug::Bignum.test_numbytes_2comp_with_sign(0x80))
|
||||
assert_equal(2, Bug::Bignum.test_numbytes_2comp_with_sign(0x7fff))
|
||||
assert_equal(3, Bug::Bignum.test_numbytes_2comp_with_sign(0x8000))
|
||||
assert_equal(3, Bug::Bignum.test_numbytes_2comp_with_sign(0x7fffff))
|
||||
assert_equal(4, Bug::Bignum.test_numbytes_2comp_with_sign(0x800000))
|
||||
assert_equal(4, Bug::Bignum.test_numbytes_2comp_with_sign(0x7fffffff))
|
||||
assert_equal(5, Bug::Bignum.test_numbytes_2comp_with_sign(0x80000000))
|
||||
assert_equal(5, Bug::Bignum.test_numbytes_2comp_with_sign(0x7fffffffff))
|
||||
assert_equal(6, Bug::Bignum.test_numbytes_2comp_with_sign(0x8000000000))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -5,32 +5,32 @@ require "-test-/bignum"
|
|||
class Test_Bignum < Test::Unit::TestCase
|
||||
class TestStr2big < Test::Unit::TestCase
|
||||
|
||||
SIZEOF_BDIGIT = Integer::SIZEOF_BDIGIT
|
||||
BITSPERDIG = Integer::BITSPERDIG
|
||||
SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
|
||||
BITSPERDIG = Bug::Bignum::BITSPERDIG
|
||||
BDIGMAX = (1 << BITSPERDIG) - 1
|
||||
|
||||
def test_str2big_poweroftwo
|
||||
s = "1" + "0" * 1000
|
||||
n = 16 ** 1000
|
||||
assert_equal(n, s.str2big_poweroftwo(16, true))
|
||||
assert_equal(n, Bug::Bignum.str2big_poweroftwo(s, 16, true))
|
||||
end
|
||||
|
||||
def test_str2big_normal
|
||||
s = "1" + "0" * 1000
|
||||
n = 10 ** 1000
|
||||
assert_equal(n, s.str2big_normal(10, true))
|
||||
assert_equal(n, Bug::Bignum.str2big_normal(s, 10, true))
|
||||
end
|
||||
|
||||
def test_str2big_karatsuba
|
||||
s = "1" + "0" * 1000
|
||||
n = 10 ** 1000
|
||||
assert_equal(n, s.str2big_karatsuba(10, true))
|
||||
assert_equal(n, Bug::Bignum.str2big_karatsuba(s, 10, true))
|
||||
end
|
||||
|
||||
def test_str2big_gmp
|
||||
s = "1" + "0" * 1000
|
||||
n = 10 ** 1000
|
||||
assert_equal(n, s.str2big_gmp(10, true))
|
||||
assert_equal(n, Bug::Bignum.str2big_gmp(s, 10, true))
|
||||
rescue NotImplementedError
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class TestLastThread < Test::Unit::TestCase
|
|||
}
|
||||
|
||||
t0 = Time.now
|
||||
Thread.current.__runnable_sleep__ 1
|
||||
Bug::Thread.runnable_sleep 1
|
||||
t1 = Time.now
|
||||
t = t1 - t0
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class TestUbfAsyncSafe < Test::Unit::TestCase
|
|||
require '-test-/gvl/call_without_gvl'
|
||||
r.close
|
||||
trap(:INT) { exit!(0) }
|
||||
Thread.current.__ubf_async_safe__(w.fileno)
|
||||
Bug::Thread.ubf_async_safe(w.fileno)
|
||||
exit!(1)
|
||||
end
|
||||
w.close
|
||||
|
|
|
@ -16,11 +16,11 @@ class Test_Integer < Test::Unit::TestCase
|
|||
def test_positive_pow
|
||||
assert_separately(%w[-r-test-/integer], "#{<<~"begin;"}\n#{<<~'end;'}", timeout: 3)
|
||||
begin;
|
||||
assert_equal(1, 1.positive_pow(1))
|
||||
assert_equal(0, 0.positive_pow(1))
|
||||
assert_equal(3, 3.positive_pow(1))
|
||||
assert_equal(-3, -3.positive_pow(1))
|
||||
assert_equal(9, -3.positive_pow(2))
|
||||
assert_equal(1, Bug::Integer.positive_pow(1, 1))
|
||||
assert_equal(0, Bug::Integer.positive_pow(0, 1))
|
||||
assert_equal(3, Bug::Integer.positive_pow(3, 1))
|
||||
assert_equal(-3, Bug::Integer.positive_pow(-3, 1))
|
||||
assert_equal(9, Bug::Integer.positive_pow(-3, 2))
|
||||
end;
|
||||
end
|
||||
end
|
||||
|
|
|
@ -101,7 +101,7 @@ class TestNum2int < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def assert_fix2i_success(type, num, result=num)
|
||||
return if !num.fixnum?
|
||||
return unless Bug::Integer.fixnum?(num)
|
||||
func = "FIX2#{type}".upcase
|
||||
assert_fix2i_success_internal(result.to_s, func, num)
|
||||
end
|
||||
|
@ -113,7 +113,7 @@ class TestNum2int < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def assert_fix2i_error(type, num)
|
||||
return if !num.fixnum?
|
||||
return unless Bug::Integer.fixnum?(num)
|
||||
func = "FIX2#{type}".upcase
|
||||
assert_num2i_error_internal(func, num)
|
||||
end
|
||||
|
|
|
@ -9,21 +9,21 @@ class TestRational < Test::Unit::TestCase
|
|||
x = 2*2*3*3*3
|
||||
y = 2*2*2*3*3
|
||||
gcd = 2*2*3*3
|
||||
assert_equal(gcd, x.gcd_normal(y))
|
||||
assert_equal(gcd, Bug::Rational.gcd_normal(x, y))
|
||||
end
|
||||
|
||||
def test_gcd_gmp
|
||||
x = 2*2*3*3*3
|
||||
y = 2*2*2*3*3
|
||||
gcd = 2*2*3*3
|
||||
assert_equal(gcd, x.gcd_gmp(y))
|
||||
assert_equal(gcd, Bug::Rational.gcd_gmp(x, y))
|
||||
rescue NotImplementedError
|
||||
end
|
||||
|
||||
def test_gcd_gmp_brute_force
|
||||
-13.upto(13) {|x|
|
||||
-13.upto(13) {|y|
|
||||
assert_equal(x.gcd_normal(y), x.gcd_gmp(y))
|
||||
assert_equal(Bug::Rational.gcd_normal(x, y), Bug::Rational.gcd_gmp(x, y))
|
||||
}
|
||||
}
|
||||
rescue NotImplementedError
|
||||
|
@ -31,39 +31,39 @@ class TestRational < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_rb_rational_raw
|
||||
rat = Rational.raw(1, 2)
|
||||
rat = Bug::Rational.raw(1, 2)
|
||||
assert_equal(1, rat.numerator)
|
||||
assert_equal(2, rat.denominator)
|
||||
|
||||
rat = Rational.raw(-1, 2)
|
||||
rat = Bug::Rational.raw(-1, 2)
|
||||
assert_equal(-1, rat.numerator)
|
||||
assert_equal(2, rat.denominator)
|
||||
|
||||
rat = Rational.raw(1, -2)
|
||||
rat = Bug::Rational.raw(1, -2)
|
||||
assert_equal(-1, rat.numerator)
|
||||
assert_equal(2, rat.denominator)
|
||||
|
||||
assert_equal(1/2r, Rational.raw(1.0, 2.0))
|
||||
assert_equal(1/2r, Bug::Rational.raw(1.0, 2.0))
|
||||
|
||||
assert_raise(TypeError) { Rational.raw("1", 2) }
|
||||
assert_raise(TypeError) { Rational.raw(1, "2") }
|
||||
assert_raise(TypeError) { Bug::Rational.raw("1", 2) }
|
||||
assert_raise(TypeError) { Bug::Rational.raw(1, "2") }
|
||||
|
||||
class << (o = Object.new)
|
||||
def to_i; 42; end
|
||||
end
|
||||
|
||||
assert_raise(TypeError) { Rational.raw(o, 2) }
|
||||
assert_raise(TypeError) { Rational.raw(1, o) }
|
||||
assert_raise(TypeError) { Bug::Rational.raw(o, 2) }
|
||||
assert_raise(TypeError) { Bug::Rational.raw(1, o) }
|
||||
|
||||
class << (o = Object.new)
|
||||
def to_int; 42; end
|
||||
end
|
||||
|
||||
rat = Rational.raw(o, 2)
|
||||
rat = Bug::Rational.raw(o, 2)
|
||||
assert_equal(42, rat.numerator)
|
||||
assert_equal(2, rat.denominator)
|
||||
|
||||
rat = Rational.raw(2, o)
|
||||
rat = Bug::Rational.raw(2, o)
|
||||
assert_equal(2, rat.numerator)
|
||||
assert_equal(42, rat.denominator)
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ if /mswin|mingw/ =~ RUBY_PLATFORM and STDOUT.tty?
|
|||
REVERSE_VIDEO = Bug::Win32::REVERSE_VIDEO
|
||||
|
||||
def reverse_video(fore, back = 0x0)
|
||||
info = STDOUT.console_info
|
||||
info = Bug::Win32.console_info(STDOUT)
|
||||
if (info.attr & REVERSE_VIDEO) == 0
|
||||
(fore << 4) | back
|
||||
else
|
||||
|
@ -17,38 +17,38 @@ if /mswin|mingw/ =~ RUBY_PLATFORM and STDOUT.tty?
|
|||
end
|
||||
|
||||
def reset
|
||||
STDOUT.console_attribute(7)
|
||||
Bug::Win32.console_attribute(STDOUT, 7)
|
||||
end
|
||||
|
||||
alias setup reset
|
||||
alias teardown reset
|
||||
|
||||
def test_default
|
||||
info = STDOUT.console_info
|
||||
info = Bug::Win32.console_info(STDOUT)
|
||||
assert_equal(7, info.attr);
|
||||
end
|
||||
|
||||
def test_reverse
|
||||
print "\e[7m"
|
||||
info = STDOUT.console_info
|
||||
info = Bug::Win32.console_info(STDOUT)
|
||||
assert_equal(reverse_video(0x7), info.attr);
|
||||
end
|
||||
|
||||
def test_bold
|
||||
print "\e[1m"
|
||||
info = STDOUT.console_info
|
||||
info = Bug::Win32.console_info(STDOUT)
|
||||
assert_equal(0x8, info.attr&0x8);
|
||||
end
|
||||
|
||||
def test_bold_reverse
|
||||
print "\e[1;7m"
|
||||
info = STDOUT.console_info
|
||||
info = Bug::Win32.console_info(STDOUT)
|
||||
assert_equal(reverse_video(0xf), info.attr);
|
||||
end
|
||||
|
||||
def test_reverse_bold
|
||||
print "\e[7;1m"
|
||||
info = STDOUT.console_info
|
||||
info = Bug::Win32.console_info(STDOUT)
|
||||
assert_equal(reverse_video(0xf), info.attr);
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,19 +19,19 @@ class TestBignum < Test::Unit::TestCase
|
|||
end
|
||||
BIGNUM_MIN_BITS = n
|
||||
|
||||
T_ZERO = 0.to_bignum
|
||||
T_ONE = 1.to_bignum
|
||||
T_MONE = (-1).to_bignum
|
||||
T31 = (2**31).to_bignum # 2147483648
|
||||
T31P = (T31 - 1).to_bignum # 2147483647
|
||||
T32 = (2**32).to_bignum # 4294967296
|
||||
T32P = (T32 - 1).to_bignum # 4294967295
|
||||
T64 = (2**64).to_bignum # 18446744073709551616
|
||||
T64P = (T64 - 1).to_bignum # 18446744073709551615
|
||||
T128 = (2**128).to_bignum
|
||||
T128P = (T128 - 1).to_bignum
|
||||
T1024 = (2**1024).to_bignum
|
||||
T1024P = (T1024 - 1).to_bignum
|
||||
T_ZERO = Bug::Integer.to_bignum(0)
|
||||
T_ONE = Bug::Integer.to_bignum(1)
|
||||
T_MONE = Bug::Integer.to_bignum(-1)
|
||||
T31 = Bug::Integer.to_bignum(2**31) # 2147483648
|
||||
T31P = Bug::Integer.to_bignum(T31 - 1) # 2147483647
|
||||
T32 = Bug::Integer.to_bignum(2**32) # 4294967296
|
||||
T32P = Bug::Integer.to_bignum(T32 - 1) # 4294967295
|
||||
T64 = Bug::Integer.to_bignum(2**64) # 18446744073709551616
|
||||
T64P = Bug::Integer.to_bignum(T64 - 1) # 18446744073709551615
|
||||
T128 = Bug::Integer.to_bignum(2**128)
|
||||
T128P = Bug::Integer.to_bignum(T128 - 1)
|
||||
T1024 = Bug::Integer.to_bignum(2**1024)
|
||||
T1024P = Bug::Integer.to_bignum(T1024 - 1)
|
||||
|
||||
def setup
|
||||
@verbose = $VERBOSE
|
||||
|
@ -682,7 +682,7 @@ class TestBignum < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_too_big_to_s
|
||||
if (big = 2**31-1).fixnum?
|
||||
if Bug::Integer.fixnum?(big = 2**31-1)
|
||||
return
|
||||
end
|
||||
assert_raise_with_message(RangeError, /too big to convert/) {(1 << big).to_s}
|
||||
|
@ -765,7 +765,7 @@ class TestBignum < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_digits
|
||||
assert_equal([90, 78, 56, 34, 12], 1234567890.to_bignum.digits(100))
|
||||
assert_equal([90, 78, 56, 34, 12], Bug::Integer.to_bignum(1234567890).digits(100))
|
||||
assert_equal([7215, 2413, 6242], T1024P.digits(10_000).first(3))
|
||||
assert_equal([11], 11.digits(T1024P))
|
||||
assert_equal([T1024P - 1, 1], (T1024P + T1024P - 1).digits(T1024P))
|
||||
|
@ -778,13 +778,13 @@ class TestBignum < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_digits_for_invalid_base_numbers
|
||||
assert_raise(ArgumentError) { T1024P.to_bignum.digits(0) }
|
||||
assert_raise(ArgumentError) { T1024P.to_bignum.digits(-1) }
|
||||
assert_raise(ArgumentError) { T1024P.to_bignum.digits(0.to_bignum) }
|
||||
assert_raise(ArgumentError) { T1024P.to_bignum.digits(1.to_bignum) }
|
||||
assert_raise(ArgumentError) { T1024P.to_bignum.digits(-T1024P) }
|
||||
assert_raise(ArgumentError) { 10.digits(0.to_bignum) }
|
||||
assert_raise(ArgumentError) { 10.digits(1.to_bignum) }
|
||||
assert_raise(ArgumentError) { Bug::Integer.to_bignum(T1024P).digits(0) }
|
||||
assert_raise(ArgumentError) { Bug::Integer.to_bignum(T1024P).digits(-1) }
|
||||
assert_raise(ArgumentError) { Bug::Integer.to_bignum(T1024P).digits(Bug::Integer.to_bignum(0)) }
|
||||
assert_raise(ArgumentError) { Bug::Integer.to_bignum(T1024P).digits(Bug::Integer.to_bignum(1)) }
|
||||
assert_raise(ArgumentError) { Bug::Integer.to_bignum(T1024P).digits(-T1024P) }
|
||||
assert_raise(ArgumentError) { 10.digits(Bug::Integer.to_bignum(0)) }
|
||||
assert_raise(ArgumentError) { 10.digits(Bug::Integer.to_bignum(1)) }
|
||||
end
|
||||
|
||||
def test_digits_for_non_integral_base_numbers
|
||||
|
|
|
@ -420,7 +420,7 @@ class TestFiber < Test::Unit::TestCase
|
|||
def test_fatal_in_fiber
|
||||
assert_in_out_err(["-r-test-/fatal/rb_fatal", "-e", <<-EOS], "", [], /ok/)
|
||||
Fiber.new{
|
||||
rb_fatal "ok"
|
||||
Bug.rb_fatal "ok"
|
||||
}.resume
|
||||
puts :ng # unreachable.
|
||||
EOS
|
||||
|
|
|
@ -4,11 +4,11 @@ require '-test-/integer.so'
|
|||
module Test::Unit::Assertions
|
||||
def assert_fixnum(v, msg=nil)
|
||||
assert_instance_of(Integer, v, msg)
|
||||
assert_predicate(v, :fixnum?, msg)
|
||||
assert_send([Bug::Integer, :fixnum?, v], msg)
|
||||
end
|
||||
|
||||
def assert_bignum(v, msg=nil)
|
||||
assert_instance_of(Integer, v, msg)
|
||||
assert_predicate(v, :bignum?, msg)
|
||||
assert_send([Bug::Integer, :bignum?, v], msg)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue