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

ruby-changes:37645

From: gogotanaka <ko1@a...>
Date: Wed, 25 Feb 2015 02:25:01 +0900 (JST)
Subject: [ruby-changes:37645] gogotanaka:r49726 (trunk): * test/ruby/test_math.rb: Use assert_infinity instead of assert_equal(1.0/0, ...).

gogotanaka	2015-02-25 02:24:45 +0900 (Wed, 25 Feb 2015)

  New Revision: 49726

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

  Log:
    * test/ruby/test_math.rb: Use assert_infinity instead of assert_equal(1.0/0, ...).
    
    * test/ruby/test_math.rb: Add tests for overriding Integer#to_f.
      [ruby-core:67919] [Misc #10809]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_math.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49725)
+++ ChangeLog	(revision 49726)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Feb 25 02:15:17 2015  Kazuki Tanaka  <gogotanaka@r...>
+
+	* test/ruby/test_math.rb: Use assert_infinity instead of assert_equal(1.0/0, ...).
+
+	* test/ruby/test_math.rb: Add tests for overriding Integer#to_f.
+	  [ruby-core:67919] [Misc #10809]
+
 Tue Feb 24 22:58:48 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* complex.c (nucomp_mul): calculate as rotation in complex plane
Index: test/ruby/test_math.rb
===================================================================
--- test/ruby/test_math.rb	(revision 49725)
+++ test/ruby/test_math.rb	(revision 49726)
@@ -143,7 +143,7 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L143
     check(1, Math.log(10, 10))
     check(2, Math.log(100, 10))
     check(Math.log(2.0 ** 64), Math.log(1 << 64))
-    assert_equal(1.0/0, Math.log(1.0/0))
+    assert_nothing_raised { assert_infinity(Math.log(1.0/0)) }
     assert_nothing_raised { assert_infinity(-Math.log(+0.0)) }
     assert_nothing_raised { assert_infinity(-Math.log(-0.0)) }
     assert_raise(Math::DomainError) { Math.log(-1.0) }
@@ -157,7 +157,7 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L157
     check(1, Math.log2(2))
     check(2, Math.log2(4))
     check(Math.log2(2.0 ** 64), Math.log2(1 << 64))
-    assert_equal(1.0/0, Math.log2(1.0/0))
+    assert_nothing_raised { assert_infinity(Math.log2(1.0/0)) }
     assert_nothing_raised { assert_infinity(-Math.log2(+0.0)) }
     assert_nothing_raised { assert_infinity(-Math.log2(-0.0)) }
     assert_raise(Math::DomainError) { Math.log2(-1.0) }
@@ -168,7 +168,7 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L168
     check(1, Math.log10(10))
     check(2, Math.log10(100))
     check(Math.log10(2.0 ** 64), Math.log10(1 << 64))
-    assert_equal(1.0/0, Math.log10(1.0/0))
+    assert_nothing_raised { assert_infinity(Math.log10(1.0/0)) }
     assert_nothing_raised { assert_infinity(-Math.log10(+0.0)) }
     assert_nothing_raised { assert_infinity(-Math.log10(-0.0)) }
     assert_raise(Math::DomainError) { Math.log10(-1.0) }
@@ -178,7 +178,7 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L178
     check(0, Math.sqrt(0))
     check(1, Math.sqrt(1))
     check(2, Math.sqrt(4))
-    assert_equal(1.0/0, Math.sqrt(1.0/0))
+    assert_nothing_raised { assert_infinity(Math.sqrt(1.0/0)) }
     assert_equal("0.0", Math.sqrt(-0.0).to_s) # insure it is +0.0, not -0.0
     assert_raise(Math::DomainError) { Math.sqrt(-1.0) }
   end
@@ -290,4 +290,33 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L290
 
     assert_raise(Math::DomainError) { Math.lgamma(-Float::INFINITY) }
   end
+
+  def test_override_fixnum_to_f
+    Fixnum.class_eval do
+      alias _to_f to_f
+      def to_f
+        (self + 1)._to_f
+      end
+    end
+
+    check(Math.cos((0 + 1)._to_f), Math.cos(0))
+    check(Math.exp((0 + 1)._to_f), Math.exp(0))
+    check(Math.log((0 + 1)._to_f), Math.log(0))
+
+    Fixnum.class_eval { alias to_f _to_f }
+  end
+
+  def test_override_bignum_to_f
+    Bignum.class_eval do
+      alias _to_f to_f
+      def to_f
+        (self << 1)._to_f
+      end
+    end
+
+    check(Math.cos((1 << 62 << 1)._to_f),  Math.cos(1 << 62))
+    check(Math.log((1 << 62 << 1)._to_f),  Math.log(1 << 62))
+
+    Bignum.class_eval { alias to_f _to_f }
+  end
 end

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

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