ruby-changes:37835
From: nobu <ko1@a...>
Date: Tue, 10 Mar 2015 20:02:12 +0900 (JST)
Subject: [ruby-changes:37835] nobu:r49916 (trunk): test_math.rb: to_f tests
nobu 2015-03-10 20:01:55 +0900 (Tue, 10 Mar 2015) New Revision: 49916 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49916 Log: test_math.rb: to_f tests * test/ruby/test_math.rb (test_{fixnum,bignum,rational}_to_f): refine to_f tests. Modified files: trunk/test/ruby/test_math.rb Index: test/ruby/test_math.rb =================================================================== --- test/ruby/test_math.rb (revision 49915) +++ test/ruby/test_math.rb (revision 49916) @@ -49,11 +49,6 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L49 check(-1.0, Math.cos(4 * Math::PI / 4)) check(0.0, Math.cos(6 * Math::PI / 4)) check(0.5403023058681398, Math.cos(1)) - check(-0.7112665029764864, Math.cos(1 << 62)) - check(0.9289154176164999, Math.cos((2 ** 62)/(3 ** 40).to_r)) - check(0.9820680774815206, Math.cos((2 ** 61)/(3 ** 40).to_r)) - check(0.4194382061248139, Math.cos((2 ** 62)/(3 ** 39).to_r)) - check(0.8424482791616391, Math.cos((2 ** 61)/(3 ** 39).to_r)) end def test_sin @@ -272,6 +267,10 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L267 assert_raise(Math::DomainError) { Math.lgamma(-Float::INFINITY) } end + def test_fixnum_to_f + check(12.0, Math.sqrt(144)) + end + def test_override_fixnum_to_f Fixnum.class_eval do alias _to_f to_f @@ -287,6 +286,10 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L286 Fixnum.class_eval { alias to_f _to_f } end + def test_bignum_to_f + check((1 << 65).to_f, Math.sqrt(1 << 130)) + end + def test_override_bignum_to_f Bignum.class_eval do alias _to_f to_f @@ -301,6 +304,10 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L304 Bignum.class_eval { alias to_f _to_f } end + def test_rational_to_f + check((2 ** 31).fdiv(3 ** 20), Math.sqrt((2 ** 62)/(3 ** 40).to_r)) + end + def test_override_rational_to_f Rational.class_eval do alias _to_f to_f -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/