diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-20 00:36:55 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-20 00:36:55 +0000 |
commit | 68354c350a278a565bc3b2b3ba793b8a9dcd2712 (patch) | |
tree | 7a35a520c4c6ca5a6661357d6a3668b8769d7e59 /test | |
parent | 825a1e939bd85e19d5a3de0411aa1fa6f23e0e99 (diff) | |
download | ruby-68354c350a278a565bc3b2b3ba793b8a9dcd2712.tar.gz |
lib/prime: Fix primality of some large integers [#13492].
* lib/prime.rb: Use accurate sqrt to insure all factors are tested.
Patch by Marcus Stollsteimer.
* test/test_prime.rb: Adapt test for timeout
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/test_prime.rb | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/test/test_prime.rb b/test/test_prime.rb index fc769c54d7..fe847eb832 100644 --- a/test/test_prime.rb +++ b/test/test_prime.rb @@ -174,20 +174,21 @@ class TestPrime < Test::Unit::TestCase def test_eratosthenes_works_fine_after_timeout sieve = Prime::EratosthenesSieve.instance sieve.send(:initialize) + # simulates that Timeout.timeout interrupts Prime::EratosthenesSieve#compute_primes + class << Integer + alias_method :org_sqrt, :sqrt + end begin - # simulates that Timeout.timeout interrupts Prime::EratosthenesSieve#compute_primes - def sieve.Integer(n) - n = super(n) + def Integer.sqrt(n) sleep 10 if /compute_primes/ =~ caller.first - return n + org_sqrt(n) end - assert_raise(Timeout::Error) do Timeout.timeout(0.5) { Prime.each(7*37){} } end ensure - class << sieve - remove_method :Integer + class << Integer + alias_method :sqrt, :org_sqrt end end |