Project

General

Profile

Bug #7395 ยป prime_refute_negative_numbers.patch

zzak (zzak _), 11/19/2012 12:40 PM

View differences:

lib/prime.rb
# +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
test/test_prime.rb
# negative
assert !-1.prime?
assert(-2.prime?)
assert(-3.prime?)
assert !-2.prime?
assert !-3.prime?
assert !-4.prime?
end
end
    (1-1/1)