ruby-changes:34940
From: nobu <ko1@a...>
Date: Fri, 1 Aug 2014 16:35:48 +0900 (JST)
Subject: [ruby-changes:34940] nobu:r47023 (trunk): add assertions for division NaN
nobu 2014-08-01 16:35:34 +0900 (Fri, 01 Aug 2014) New Revision: 47023 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47023 Log: add assertions for division NaN Modified files: trunk/test/ruby/test_fixnum.rb trunk/test/ruby/test_float.rb Index: test/ruby/test_float.rb =================================================================== --- test/ruby/test_float.rb (revision 47022) +++ test/ruby/test_float.rb (revision 47023) @@ -168,6 +168,8 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L168 assert_equal([-3, -0.5], 11.5.divmod(-4)) assert_equal([-3, 0.5], (-11.5).divmod(4)) assert_equal([2, -3.5], (-11.5).divmod(-4)) + assert_raise(FloatDomainError) { Float::NAN.divmod(2) } + assert_raise(FloatDomainError) { Float::INFINITY.divmod(2) } end def test_div @@ -175,6 +177,9 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L177 assert_equal(-3, 11.5.div(-4)) assert_equal(-3, (-11.5).div(4)) assert_equal(2, (-11.5).div(-4)) + assert_raise(FloatDomainError) { 11.5.div(Float::NAN).nan? } + assert_raise(FloatDomainError) { Float::NAN.div(2).nan? } + assert_raise(FloatDomainError) { Float::NAN.div(11.5).nan? } end def test_modulo @@ -189,6 +194,8 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L194 assert_equal(3.5, 11.5.remainder(-4)) assert_equal(-3.5, (-11.5).remainder(4)) assert_equal(-3.5, (-11.5).remainder(-4)) + assert_predicate(Float::NAN.remainder(4), :nan?) + assert_predicate(4.remainder(Float::NAN), :nan?) end def test_to_s @@ -215,6 +222,8 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L222 assert_equal(4.0, 2.0.send(:+, 2)) assert_equal(4.0, 2.0.send(:+, (2**32).coerce(2).first)) assert_equal(4.0, 2.0.send(:+, 2.0)) + assert_equal(Float::INFINITY, 2.0.send(:+, Float::INFINITY)) + assert_predicate(2.0.send(:+, Float::NAN), :nan?) assert_raise(TypeError) { 2.0.send(:+, nil) } end @@ -222,6 +231,8 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L231 assert_equal(0.0, 2.0.send(:-, 2)) assert_equal(0.0, 2.0.send(:-, (2**32).coerce(2).first)) assert_equal(0.0, 2.0.send(:-, 2.0)) + assert_equal(-Float::INFINITY, 2.0.send(:-, Float::INFINITY)) + assert_predicate(2.0.send(:-, Float::NAN), :nan?) assert_raise(TypeError) { 2.0.send(:-, nil) } end @@ -229,6 +240,7 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L240 assert_equal(4.0, 2.0.send(:*, 2)) assert_equal(4.0, 2.0.send(:*, (2**32).coerce(2).first)) assert_equal(4.0, 2.0.send(:*, 2.0)) + assert_equal(Float::INFINITY, 2.0.send(:*, Float::INFINITY)) assert_raise(TypeError) { 2.0.send(:*, nil) } end @@ -236,6 +248,7 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L248 assert_equal(1.0, 2.0.send(:/, 2)) assert_equal(1.0, 2.0.send(:/, (2**32).coerce(2).first)) assert_equal(1.0, 2.0.send(:/, 2.0)) + assert_equal(0.0, 2.0.send(:/, Float::INFINITY)) assert_raise(TypeError) { 2.0.send(:/, nil) } end @@ -630,7 +643,7 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L643 assert_equal(Float::EPSILON, 1.0.next_float - 1.0) assert_equal(Float::INFINITY, Float::MAX.next_float) assert_equal(Float::INFINITY, Float::INFINITY.next_float) - assert(Float::NAN.next_float.nan?) + assert_predicate(Float::NAN.next_float, :nan?) end def test_prev_float @@ -643,7 +656,7 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L656 assert_equal(-Float::EPSILON/2, 1.0.prev_float - 1.0) assert_operator(Float::MAX, :>, Float::MAX.prev_float) assert_equal(Float::MAX, Float::INFINITY.prev_float) - assert(Float::NAN.prev_float.nan?) + assert_predicate(Float::NAN.prev_float, :nan?) end def test_next_prev_float_zero Index: test/ruby/test_fixnum.rb =================================================================== --- test/ruby/test_fixnum.rb (revision 47022) +++ test/ruby/test_fixnum.rb (revision 47023) @@ -74,6 +74,7 @@ class TestFixnum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fixnum.rb#L74 assert_equal(-0x4000000000000001, 0xc000000000000003/(-3)) assert_equal(0x40000000, (-0x40000000)/(-1), "[ruby-dev:31210]") assert_equal(0x4000000000000000, (-0x4000000000000000)/(-1)) + assert_raise(FloatDomainError) { 2.div(Float::NAN).nan? } end def test_mod @@ -101,6 +102,7 @@ class TestFixnum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fixnum.rb#L102 assert_equal(r, a.modulo(b)) } } + assert_raise(FloatDomainError) { 2.divmod(Float::NAN) } end def test_not @@ -305,4 +307,9 @@ class TestFixnum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fixnum.rb#L307 assert_raise(ZeroDivisionError, bug5713) { 0 ** -big } assert_raise(ZeroDivisionError, bug5713) { 0 ** Rational(-2,3) } end + + def test_remainder + assert_equal(1, 5.remainder(4)) + assert_predicate(4.remainder(Float::NAN), :nan?) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/