summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2020-10-12 13:42:48 +0900
committerYusuke Endoh <mame@ruby-lang.org>2020-10-12 13:42:48 +0900
commit8a39e6d6539bd37100cbbfb88916b853f444f771 (patch)
tree5ea6f50cfa0f2cb92c4e7f6da341bed41e1105c6 /test
parent1336698294250ec78b4d33e0a52f8afb55e987d3 (diff)
bignum.c (rb_int_powm): Integer#pow(0, 1) should return 0
... instead of 1 because it requires "modulo 1". [Bug #17257]
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_numeric.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb
index 7ea02fdcbf..0fcf385c0d 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -435,6 +435,26 @@ class TestNumeric < Test::Unit::TestCase
assert_equal(12, 12.pow(1, 10000000001), '[Bug #14259]')
assert_equal(12, 12.pow(1, 10000000002), '[Bug #14259]')
assert_equal(17298641040, 12.pow(72387894339363242, 243682743764), '[Bug #14259]')
+
+ integers = [-2, -1, 0, 1, 2, 3, 6, 1234567890123456789]
+ integers.each do |i|
+ assert_equal(0, i.pow(0, 1), '[Bug #17257]')
+ assert_equal(1, i.pow(0, 2))
+ assert_equal(1, i.pow(0, 3))
+ assert_equal(1, i.pow(0, 6))
+ assert_equal(1, i.pow(0, 1234567890123456789))
+
+ assert_equal(0, i.pow(0, -1))
+ assert_equal(-1, i.pow(0, -2))
+ assert_equal(-2, i.pow(0, -3))
+ assert_equal(-5, i.pow(0, -6))
+ assert_equal(-1234567890123456788, i.pow(0, -1234567890123456789))
+ end
+
+ assert_equal(0, 0.pow(2, 1))
+ assert_equal(0, 0.pow(3, 1))
+ assert_equal(0, 2.pow(3, 1))
+ assert_equal(0, -2.pow(3, 1))
end
end