1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/-ext-/num2int/test_num2int.rb (asert_num2i_success): New

utility method.
  (asert_num2i_error): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-03-27 12:01:40 +00:00
parent c64f26a281
commit 7379116878
2 changed files with 82 additions and 171 deletions

View file

@ -1,8 +1,14 @@
Wed Mar 27 12:45:41 2013 Tanaka Akira <akr@fsij.org>
Wed Mar 27 20:59:47 2013 Tanaka Akira <akr@fsij.org>
* time.c (num_exact): use to_r method only if to_int method is
* test/-ext-/num2int/test_num2int.rb (asert_num2i_success): New
utility method.
(asert_num2i_error): Ditto.
Wed Mar 27 20:37:59 2013 Tanaka Akira <akr@fsij.org>
* time.c (num_exact): Use to_r method only if to_int method is
available.
[ruby-core:53764] [Bug #8173] reported by Hiro Asari.
[ruby-core:53764] [Bug #8173] Reported by Hiro Asari.
Wed Mar 27 12:07:40 2013 Tanaka Akira <akr@fsij.org>

View file

@ -31,196 +31,101 @@ class TestNum2int < Test::Unit::TestCase
FIXNUM_MAX = LONG_MAX/2
FIXNUM_MIN = LONG_MIN/2
def asert_num2i_success(type, num, result=num)
method = "print_num2#{type}"
assert_output(result.to_s) do
Num2int.send(method, num)
end
end
def asert_num2i_error(type, num)
method = "print_num2#{type}"
assert_raise(RangeError) do
Num2int.send(method, num)
end
end
def test_num2short
assert_output(SHRT_MIN.to_s) do
Num2int.print_num2short(SHRT_MIN)
end
assert_output(SHRT_MAX.to_s) do
Num2int.print_num2short(SHRT_MAX)
end
assert_raise(RangeError) do
Num2int.print_num2short(SHRT_MIN-1)
end
assert_raise(RangeError) do
Num2int.print_num2short(SHRT_MAX+1)
end
asert_num2i_success(:short, SHRT_MIN)
asert_num2i_success(:short, SHRT_MAX)
asert_num2i_error(:short, SHRT_MIN-1)
asert_num2i_error(:short, SHRT_MAX+1)
end
def test_num2ushort
assert_output("0") do
Num2int.print_num2ushort(0)
end
assert_output(USHRT_MAX.to_s) do
Num2int.print_num2ushort(USHRT_MAX)
end
assert_output(USHRT_MAX.to_s) do
Num2int.print_num2ushort(-1)
end
assert_output((SHRT_MAX+1).to_s) do
Num2int.print_num2ushort(SHRT_MIN)
end
assert_raise(RangeError) do
Num2int.print_num2ushort(SHRT_MIN-1)
end
assert_raise(RangeError) do
Num2int.print_num2ushort(USHRT_MAX+1)
end
asert_num2i_success(:ushort, 0)
asert_num2i_success(:ushort, USHRT_MAX)
asert_num2i_success(:ushort, -1, USHRT_MAX)
asert_num2i_success(:ushort, SHRT_MIN, SHRT_MAX+1)
asert_num2i_error(:ushort, SHRT_MIN-1)
asert_num2i_error(:ushort, USHRT_MAX+1)
end
def test_num2int
assert_output(INT_MIN.to_s) do
Num2int.print_num2int(INT_MIN)
end
assert_output(INT_MAX.to_s) do
Num2int.print_num2int(INT_MAX)
end
assert_raise(RangeError) do
Num2int.print_num2int(INT_MIN-1)
end
assert_raise(RangeError) do
Num2int.print_num2int(INT_MAX+1)
end
asert_num2i_success(:int, INT_MIN)
asert_num2i_success(:int, INT_MAX)
asert_num2i_error(:int, INT_MIN-1)
asert_num2i_error(:int, INT_MAX+1)
end
def test_num2uint
assert_output("0") do
Num2int.print_num2uint(0)
end
assert_output(UINT_MAX.to_s) do
Num2int.print_num2uint(UINT_MAX)
end
assert_output(UINT_MAX.to_s) do
Num2int.print_num2uint(-1)
end
assert_output((INT_MAX+1).to_s) do
Num2int.print_num2uint(INT_MIN)
end
assert_raise(RangeError) do
Num2int.print_num2uint(INT_MIN-1)
end
assert_raise(RangeError) do
Num2int.print_num2uint(UINT_MAX+1)
end
asert_num2i_success(:uint, 0)
asert_num2i_success(:uint, UINT_MAX)
asert_num2i_success(:uint, -1, UINT_MAX)
asert_num2i_success(:uint, INT_MIN, INT_MAX+1)
asert_num2i_error(:uint, INT_MIN-1)
asert_num2i_error(:uint, UINT_MAX+1)
end
def test_num2long
assert_output(LONG_MIN.to_s) do
Num2int.print_num2long(LONG_MIN)
end
assert_output(LONG_MAX.to_s) do
Num2int.print_num2long(LONG_MAX)
end
assert_raise(RangeError) do
Num2int.print_num2long(LONG_MIN-1)
end
assert_raise(RangeError) do
Num2int.print_num2long(LONG_MAX+1)
end
assert_output(FIXNUM_MIN.to_s) do
Num2int.print_num2long(FIXNUM_MIN)
end
assert_output((FIXNUM_MIN-1).to_s) do
Num2int.print_num2long(FIXNUM_MIN-1)
end
assert_output(FIXNUM_MAX.to_s) do
Num2int.print_num2long(FIXNUM_MAX)
end
assert_output((FIXNUM_MAX+1).to_s) do
Num2int.print_num2long(FIXNUM_MAX+1)
end
#assert_output(LONG_MIN.to_s) do
# Num2int.print_num2long(LONG_MIN.to_f)
#end
asert_num2i_success(:long, LONG_MIN)
asert_num2i_success(:long, LONG_MAX)
asert_num2i_error(:long, LONG_MIN-1)
asert_num2i_error(:long, LONG_MAX+1)
asert_num2i_success(:long, FIXNUM_MIN)
asert_num2i_success(:long, FIXNUM_MIN-1)
asert_num2i_success(:long, FIXNUM_MAX)
asert_num2i_success(:long, FIXNUM_MAX+1)
end
def test_num2ulong
assert_output("0") do
Num2int.print_num2ulong(0)
end
assert_output(ULONG_MAX.to_s) do
Num2int.print_num2ulong(ULONG_MAX)
end
assert_output(ULONG_MAX.to_s) do
Num2int.print_num2ulong(-1)
end
assert_output((LONG_MAX+1).to_s) do
Num2int.print_num2ulong(LONG_MIN)
end
assert_raise(RangeError) do
Num2int.print_num2ulong(LONG_MIN-1)
end
assert_raise(RangeError) do
Num2int.print_num2ulong(ULONG_MAX+1)
end
assert_output((ULONG_MAX-FIXNUM_MAX).to_s) do
Num2int.print_num2ulong(FIXNUM_MIN)
end
assert_output((ULONG_MAX-FIXNUM_MAX-1).to_s) do
Num2int.print_num2ulong(FIXNUM_MIN-1)
end
assert_output(FIXNUM_MAX.to_s) do
Num2int.print_num2ulong(FIXNUM_MAX)
end
assert_output((FIXNUM_MAX+1).to_s) do
Num2int.print_num2ulong(FIXNUM_MAX+1)
end
asert_num2i_success(:ulong, 0)
asert_num2i_success(:ulong, ULONG_MAX)
asert_num2i_success(:ulong, -1, ULONG_MAX)
asert_num2i_success(:ulong, LONG_MIN, LONG_MAX+1)
asert_num2i_error(:ulong, LONG_MIN-1)
asert_num2i_error(:ulong, ULONG_MAX+1)
asert_num2i_success(:ulong, FIXNUM_MIN, ULONG_MAX-FIXNUM_MAX)
asert_num2i_success(:ulong, FIXNUM_MIN-1, ULONG_MAX-FIXNUM_MAX-1)
asert_num2i_success(:ulong, FIXNUM_MAX, FIXNUM_MAX)
asert_num2i_success(:ulong, FIXNUM_MAX+1, FIXNUM_MAX+1)
end
def test_num2ll
assert_output(LLONG_MIN.to_s) do
Num2int.print_num2ll(LLONG_MIN)
end
assert_output(LLONG_MAX.to_s) do
Num2int.print_num2ll(LLONG_MAX)
end
assert_raise(RangeError) do
Num2int.print_num2ll(LLONG_MIN-1)
end
assert_raise(RangeError) do
Num2int.print_num2ll(LLONG_MAX+1)
end
assert_output(FIXNUM_MIN.to_s) do
Num2int.print_num2ll(FIXNUM_MIN)
end
assert_output((FIXNUM_MIN-1).to_s) do
Num2int.print_num2ll(FIXNUM_MIN-1)
end
assert_output(FIXNUM_MAX.to_s) do
Num2int.print_num2ll(FIXNUM_MAX)
end
assert_output((FIXNUM_MAX+1).to_s) do
Num2int.print_num2ll(FIXNUM_MAX+1)
end
asert_num2i_success(:ll, LLONG_MIN)
asert_num2i_success(:ll, LLONG_MAX)
asert_num2i_error(:ll, LLONG_MIN-1)
asert_num2i_error(:ll, LLONG_MAX+1)
asert_num2i_success(:ll, FIXNUM_MIN)
asert_num2i_success(:ll, FIXNUM_MIN-1)
asert_num2i_success(:ll, FIXNUM_MAX)
asert_num2i_success(:ll, FIXNUM_MAX+1)
end if defined?(Num2int.print_num2ll)
def test_num2ull
assert_output("0") do
Num2int.print_num2ull(0)
end
assert_output(ULLONG_MAX.to_s) do
Num2int.print_num2ull(ULLONG_MAX)
end
assert_output(ULLONG_MAX.to_s) do
Num2int.print_num2ull(-1)
end
assert_output((LLONG_MAX+1).to_s) do
Num2int.print_num2ull(LLONG_MIN)
end
assert_raise(RangeError) do
Num2int.print_num2ull(LLONG_MIN-1)
end
assert_raise(RangeError) do
Num2int.print_num2ull(ULLONG_MAX+1)
end
assert_output((ULLONG_MAX-FIXNUM_MAX).to_s) do
Num2int.print_num2ull(FIXNUM_MIN)
end
assert_output((ULLONG_MAX-FIXNUM_MAX-1).to_s) do
Num2int.print_num2ull(FIXNUM_MIN-1)
end
assert_output(FIXNUM_MAX.to_s) do
Num2int.print_num2ull(FIXNUM_MAX)
end
assert_output((FIXNUM_MAX+1).to_s) do
Num2int.print_num2ull(FIXNUM_MAX+1)
end
asert_num2i_success(:ull, 0)
asert_num2i_success(:ull, ULLONG_MAX)
asert_num2i_success(:ull, -1, ULLONG_MAX)
asert_num2i_success(:ull, LLONG_MIN, LLONG_MAX+1)
asert_num2i_error(:ull, LLONG_MIN-1)
asert_num2i_error(:ull, ULLONG_MAX+1)
asert_num2i_success(:ull, FIXNUM_MIN, ULLONG_MAX-FIXNUM_MAX)
asert_num2i_success(:ull, FIXNUM_MIN-1, ULLONG_MAX-FIXNUM_MAX-1)
asert_num2i_success(:ull, FIXNUM_MAX)
asert_num2i_success(:ull, FIXNUM_MAX+1)
end if defined?(Num2int.print_num2ull)
end