summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_fixnum.rb7
-rw-r--r--test/ruby/test_float.rb17
2 files changed, 22 insertions, 2 deletions
diff --git a/test/ruby/test_fixnum.rb b/test/ruby/test_fixnum.rb
index c86cba3b7c..8b2cf2e256 100644
--- a/test/ruby/test_fixnum.rb
+++ b/test/ruby/test_fixnum.rb
@@ -74,6 +74,7 @@ class TestFixnum < Test::Unit::TestCase
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
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
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
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb
index ed8f2992ed..099f9e3b10 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