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

ruby-changes:27993

From: akr <ko1@a...>
Date: Tue, 2 Apr 2013 07:41:23 +0900 (JST)
Subject: [ruby-changes:27993] akr:r40045 (trunk): more tests.

akr	2013-04-02 07:41:13 +0900 (Tue, 02 Apr 2013)

  New Revision: 40045

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

  Log:
    more tests.

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

Index: test/-ext-/num2int/test_num2int.rb
===================================================================
--- test/-ext-/num2int/test_num2int.rb	(revision 40044)
+++ test/-ext-/num2int/test_num2int.rb	(revision 40045)
@@ -48,16 +48,21 @@ class TestNum2int < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L48
     func = "NUM2#{type}".upcase
     assert_num2i_success_internal(result.to_s, func, num)
     assert_num2i_success_internal(result.to_s, func, fix2big(num))
+    assert_num2i_success_internal(result.to_s, func, Rational(num, 1))
     if num.to_f.to_i == num
       assert_num2i_success_internal(result.to_s, func, num.to_f)
     end
     # The conversion functions such as NUM2INT uses (conceptually) to_int.
-    arg = num.to_f + 0.5
-    if arg != num.to_f && arg.to_int == num
+    if (arg = num.to_f + 0.5) != num.to_f && arg.to_int == num
       assert_num2i_success_internal(result.to_s, func, arg)
     end
-    arg = num.to_f - 0.5
-    if arg != num.to_f && arg.to_int == num
+    if (arg = num.to_f - 0.5) != num.to_f && arg.to_int == num
+      assert_num2i_success_internal(result.to_s, func, arg)
+    end
+    if (arg = num + Rational(1,2)) && arg.to_int == num
+      assert_num2i_success_internal(result.to_s, func, arg)
+    end
+    if (arg = num - Rational(1,2)) && arg.to_int == num
       assert_num2i_success_internal(result.to_s, func, arg)
     end
   end
@@ -72,16 +77,21 @@ class TestNum2int < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L77
     func = "NUM2#{type}".upcase
     assert_num2i_error_internal(func, num)
     assert_num2i_error_internal(func, fix2big(num))
+    assert_num2i_error_internal(func, Rational(num, 1))
     if num.to_f.to_i == num
       assert_num2i_error_internal(func, num.to_f)
     end
     # The conversion functions such as NUM2INT uses (conceptually) to_int.
-    arg = num.to_f + 0.5
-    if arg != num.to_f && arg.to_int == num
+    if (arg = num.to_f + 0.5) != num.to_f && arg.to_int == num
+      assert_num2i_error_internal(func, arg)
+    end
+    if (arg = num.to_f - 0.5) != num.to_f && arg.to_int == num
+      assert_num2i_error_internal(func, arg)
+    end
+    if (arg = num + Rational(1,2)) && arg.to_int == num
       assert_num2i_error_internal(func, arg)
     end
-    arg = num.to_f - 0.5
-    if arg != num.to_f && arg.to_int == num
+    if (arg = num - Rational(1,2)) && arg.to_int == num
       assert_num2i_error_internal(func, arg)
     end
   end

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

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