[前][次][番号順一覧][スレッド一覧]

ruby-changes:27916

From: akr <ko1@a...>
Date: Wed, 27 Mar 2013 21:01:56 +0900 (JST)
Subject: [ruby-changes:27916] akr:r39968 (trunk): * test/-ext-/num2int/test_num2int.rb (asert_num2i_success): New

akr	2013-03-27 21:01:40 +0900 (Wed, 27 Mar 2013)

  New Revision: 39968

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39968

  Log:
    * test/-ext-/num2int/test_num2int.rb (asert_num2i_success): New
      utility method.
      (asert_num2i_error): Ditto.

  Modified files:
    trunk/ChangeLog
    trunk/test/-ext-/num2int/test_num2int.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39967)
+++ ChangeLog	(revision 39968)
@@ -1,8 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Wed Mar 27 12:45:41 2013  Tanaka Akira  <akr@f...>
+Wed Mar 27 20:59:47 2013  Tanaka Akira  <akr@f...>
 
-	* 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@f...>
+
+	* 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@f...>
 
Index: test/-ext-/num2int/test_num2int.rb
===================================================================
--- test/-ext-/num2int/test_num2int.rb	(revision 39967)
+++ test/-ext-/num2int/test_num2int.rb	(revision 39968)
@@ -31,196 +31,101 @@ class TestNum2int < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L31
   FIXNUM_MAX = LONG_MAX/2
   FIXNUM_MIN = LONG_MIN/2
 
-  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)
+  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.print_num2short(SHRT_MAX+1)
+      Num2int.send(method, num)
     end
   end
 
+  def test_num2short
+    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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]