1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

add assertions for division NaN

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-08-01 07:35:34 +00:00
parent 4514516b22
commit 528ef3ca93
2 changed files with 22 additions and 2 deletions

View file

@ -74,6 +74,7 @@ class TestFixnum < Test::Unit::TestCase
assert_equal(-0x4000000000000001, 0xc000000000000003/(-3)) assert_equal(-0x4000000000000001, 0xc000000000000003/(-3))
assert_equal(0x40000000, (-0x40000000)/(-1), "[ruby-dev:31210]") assert_equal(0x40000000, (-0x40000000)/(-1), "[ruby-dev:31210]")
assert_equal(0x4000000000000000, (-0x4000000000000000)/(-1)) assert_equal(0x4000000000000000, (-0x4000000000000000)/(-1))
assert_raise(FloatDomainError) { 2.div(Float::NAN).nan? }
end end
def test_mod def test_mod
@ -101,6 +102,7 @@ class TestFixnum < Test::Unit::TestCase
assert_equal(r, a.modulo(b)) assert_equal(r, a.modulo(b))
} }
} }
assert_raise(FloatDomainError) { 2.divmod(Float::NAN) }
end end
def test_not def test_not
@ -305,4 +307,9 @@ class TestFixnum < Test::Unit::TestCase
assert_raise(ZeroDivisionError, bug5713) { 0 ** -big } assert_raise(ZeroDivisionError, bug5713) { 0 ** -big }
assert_raise(ZeroDivisionError, bug5713) { 0 ** Rational(-2,3) } assert_raise(ZeroDivisionError, bug5713) { 0 ** Rational(-2,3) }
end end
def test_remainder
assert_equal(1, 5.remainder(4))
assert_predicate(4.remainder(Float::NAN), :nan?)
end
end end

View file

@ -168,6 +168,8 @@ class TestFloat < Test::Unit::TestCase
assert_equal([-3, -0.5], 11.5.divmod(-4)) assert_equal([-3, -0.5], 11.5.divmod(-4))
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_equal([2, -3.5], (-11.5).divmod(-4))
assert_raise(FloatDomainError) { Float::NAN.divmod(2) }
assert_raise(FloatDomainError) { Float::INFINITY.divmod(2) }
end end
def test_div def test_div
@ -175,6 +177,9 @@ class TestFloat < Test::Unit::TestCase
assert_equal(-3, 11.5.div(-4)) assert_equal(-3, 11.5.div(-4))
assert_equal(-3, (-11.5).div(4)) assert_equal(-3, (-11.5).div(4))
assert_equal(2, (-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 end
def test_modulo def test_modulo
@ -189,6 +194,8 @@ class TestFloat < Test::Unit::TestCase
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_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 end
def test_to_s def test_to_s
@ -215,6 +222,8 @@ class TestFloat < Test::Unit::TestCase
assert_equal(4.0, 2.0.send(:+, 2)) 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**32).coerce(2).first))
assert_equal(4.0, 2.0.send(:+, 2.0)) 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) } assert_raise(TypeError) { 2.0.send(:+, nil) }
end end
@ -222,6 +231,8 @@ class TestFloat < Test::Unit::TestCase
assert_equal(0.0, 2.0.send(:-, 2)) 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**32).coerce(2).first))
assert_equal(0.0, 2.0.send(:-, 2.0)) 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) } assert_raise(TypeError) { 2.0.send(:-, nil) }
end end
@ -229,6 +240,7 @@ class TestFloat < Test::Unit::TestCase
assert_equal(4.0, 2.0.send(:*, 2)) 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**32).coerce(2).first))
assert_equal(4.0, 2.0.send(:*, 2.0)) 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) } assert_raise(TypeError) { 2.0.send(:*, nil) }
end end
@ -236,6 +248,7 @@ class TestFloat < Test::Unit::TestCase
assert_equal(1.0, 2.0.send(:/, 2)) 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**32).coerce(2).first))
assert_equal(1.0, 2.0.send(:/, 2.0)) 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) } assert_raise(TypeError) { 2.0.send(:/, nil) }
end end
@ -630,7 +643,7 @@ class TestFloat < Test::Unit::TestCase
assert_equal(Float::EPSILON, 1.0.next_float - 1.0) assert_equal(Float::EPSILON, 1.0.next_float - 1.0)
assert_equal(Float::INFINITY, Float::MAX.next_float) assert_equal(Float::INFINITY, Float::MAX.next_float)
assert_equal(Float::INFINITY, Float::INFINITY.next_float) assert_equal(Float::INFINITY, Float::INFINITY.next_float)
assert(Float::NAN.next_float.nan?) assert_predicate(Float::NAN.next_float, :nan?)
end end
def test_prev_float def test_prev_float
@ -643,7 +656,7 @@ class TestFloat < Test::Unit::TestCase
assert_equal(-Float::EPSILON/2, 1.0.prev_float - 1.0) assert_equal(-Float::EPSILON/2, 1.0.prev_float - 1.0)
assert_operator(Float::MAX, :>, Float::MAX.prev_float) assert_operator(Float::MAX, :>, Float::MAX.prev_float)
assert_equal(Float::MAX, Float::INFINITY.prev_float) assert_equal(Float::MAX, Float::INFINITY.prev_float)
assert(Float::NAN.prev_float.nan?) assert_predicate(Float::NAN.prev_float, :nan?)
end end
def test_next_prev_float_zero def test_next_prev_float_zero