summaryrefslogtreecommitdiff
path: root/test/ruby/test_float.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_float.rb')
-rw-r--r--test/ruby/test_float.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb
index ed8f2992ed5..099f9e3b10c 100644
--- a/test/ruby/test_float.rb
+++ b/test/ruby/test_float.rb
@@ -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([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
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
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
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
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
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
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
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
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