ruby-changes:11546
From: yugui <ko1@a...>
Date: Sun, 12 Apr 2009 23:03:14 +0900 (JST)
Subject: [ruby-changes:11546] Ruby:r23176 (ruby_1_9_1): merges r22741 from trunk into ruby_1_9_1.
yugui 2009-04-12 23:02:19 +0900 (Sun, 12 Apr 2009) New Revision: 23176 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23176 Log: merges r22741 from trunk into ruby_1_9_1. -- * lib/prime.rb (Prime::prime?): used to return a wrong answer. [ruby-core:22646]. * test/test_prime.rb (test_prime?): test case for [ruby-core:22646]. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/lib/prime.rb branches/ruby_1_9_1/test/test_prime.rb Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 23175) +++ ruby_1_9_1/ChangeLog (revision 23176) @@ -1,3 +1,10 @@ +Wed Mar 4 00:54:43 2009 Yuki Sonoda (Yugui) <yugui@y...> + + * lib/prime.rb (Prime::prime?): used to return a wrong answer. + [ruby-core:22646]. + + * test/test_prime.rb (test_prime?): test case for [ruby-core:22646]. + Thu Mar 5 11:27:16 2009 Nobuyoshi Nakada <nobu@r...> * win32/Makefile.sub (miniruby.exe): workaround for a failure of Index: ruby_1_9_1/lib/prime.rb =================================================================== --- ruby_1_9_1/lib/prime.rb (revision 23175) +++ ruby_1_9_1/lib/prime.rb (revision 23176) @@ -144,6 +144,8 @@ # +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 return true if q < num Index: ruby_1_9_1/test/test_prime.rb =================================================================== --- ruby_1_9_1/test/test_prime.rb (revision 23175) +++ ruby_1_9_1/test/test_prime.rb (revision 23176) @@ -89,6 +89,11 @@ end end + def test_default_instance_does_not_have_compatibility_methods + assert !Prime.instance.respond_to?(:succ) + assert !Prime.instance.respond_to?(:next) + end + class TestInteger < Test::Unit::TestCase def test_prime_division pd = PRIMES.inject(&:*).prime_division @@ -100,6 +105,10 @@ end def test_prime? + # zero and unit + assert !0.prime? + assert !1.prime? + # small primes assert 2.prime? assert 3.prime? @@ -121,6 +130,12 @@ # factorial assert !(2...100).inject(&:*).prime? + + # negative + assert !-1.prime? + assert -2.prime? + assert -3.prime? + assert !-4.prime? end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/