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

* lib/prime.rb (Prime#prime?): negative numbers can't be primes

by definition. reported by Ivan Kataitsev. [Bug #7395]
* test/test_prime.rb: add test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45878 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ayumin 2014-05-08 18:22:29 +00:00
parent 16b8aadc75
commit bef8e4557c
3 changed files with 8 additions and 3 deletions

View file

@ -1,3 +1,9 @@
Fri May 9 03:07:09 2014 Ayumu AIZAWA <ayumu.aizawa@gmail.com>
* lib/prime.rb (Prime#prime?): negative numbers can't be primes
by definition. reported by Ivan Kataitsev. [Bug #7395]
* test/test_prime.rb: add test.
Thu May 8 14:34:29 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* class.c (rb_mod_init_copy): always clear instance variable,

View file

@ -157,7 +157,6 @@ class Prime
# +value+:: an arbitrary integer to be checked.
# +generator+:: optional. A pseudo-prime generator.
def prime?(value, generator = Prime::Generator23.new)
value = -value if value < 0
return false if value < 2
for num in generator
q,r = value.divmod num

View file

@ -141,8 +141,8 @@ class TestPrime < Test::Unit::TestCase
# negative
assert !-1.prime?
assert(-2.prime?)
assert(-3.prime?)
assert !-2.prime?
assert !-3.prime?
assert !-4.prime?
end
end