summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ruby/envutil.rb4
-rw-r--r--test/ruby/test_float.rb12
2 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb
index 80700d6dc5..3e0c1a3f00 100644
--- a/test/ruby/envutil.rb
+++ b/test/ruby/envutil.rb
@@ -212,6 +212,10 @@ module Test
assert_equal([true, ""], [status.success?, err], message)
assert_operator(after.fdiv(before), :<, limit, message)
end
+
+ def assert_is_minus_zero(f)
+ assert(1.0/f == -Float::INFINITY, "#{f} is not -0.0")
+ end
end
end
end
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb
index 1935cfdd52..f561d00158 100644
--- a/test/ruby/test_float.rb
+++ b/test/ruby/test_float.rb
@@ -195,6 +195,18 @@ class TestFloat < Test::Unit::TestCase
assert_raise(TypeError) { 2.0.send(:%, nil) }
end
+ def test_modulo3
+ bug6048 = '[ruby-core:42726]'
+ assert_equal(4.2, 4.2.send(:%, Float::INFINITY))
+ assert_equal(4.2, 4.2 % Float::INFINITY)
+ assert_is_minus_zero(-0.0 % 4.2)
+ assert_is_minus_zero(-0.0.send :%, 4.2)
+ assert_raise(ZeroDivisionError) { 4.2.send(:%, 0.0) }
+ assert_raise(ZeroDivisionError) { 4.2 % 0.0 }
+ assert_raise(ZeroDivisionError) { 42.send(:%, 0) }
+ assert_raise(ZeroDivisionError) { 42 % 0 }
+ end
+
def test_divmod2
assert_equal([1.0, 0.0], 2.0.divmod(2))
assert_equal([1.0, 0.0], 2.0.divmod((2**32).coerce(2).first))