def testIsPrime(self): limit = 100 primes = intalg.primes_upto(limit) self.assertEquals(97, primes[-1]) primes2 = [n for n in xrange(limit + 1) if intalg.is_prime(n)] self.assertEquals(primes, primes2) self.assertEquals('True', repr(intalg.is_prime(97))) self.assertEquals('False', repr(intalg.is_prime(98))) self.assertEquals('False', repr(intalg.is_prime(99))) self.assertEquals('False', repr(intalg.is_prime(100))) self.assertEquals([1], intalg._prime_cache_limit_ary[:]) intalg.prime_index(257) self.assertEquals([512], intalg._prime_cache_limit_ary[:]) primes3 = [n for n in xrange(99) if intalg.is_prime(n)] self.assertEquals(primes, primes3) limit = 1009 primes = intalg.primes_upto(limit) self.assertEquals(1009, primes[-1]) primes2 = [n for n in xrange(limit + 1) if intalg.is_prime(n)] self.assertEquals(primes, primes2) del intalg._prime_cache[:] primes4 = [n for n in xrange(99) if intalg.is_prime(n)] self.assertEquals([2], primes4) # Because of the fake empty _prime_cache.
def testPrimesUpto(self): self.assertEquals([2, 3, 5, 7, 11, 13, 17, 19], intalg.primes_upto(22)) self.assertEquals([2, 3, 5, 7, 11, 13, 17, 19, 23], intalg.primes_upto(23)) self.assertEquals([2, 3, 5, 7, 11, 13, 17, 19, 23], intalg.primes_upto(24)) primes = intalg.primes_upto(100) self.assertEquals([1], intalg._prime_cache_limit_ary[:]) self.assertEquals(None, intalg.prime_index(100)) self.assertEquals(len(primes) - 1, intalg.prime_index(97)) self.assertEquals(primes, intalg.primes_upto(100)) self.assertEquals(primes, intalg.primes_upto(97)) intalg._prime_cache[:] = [6, 77, 8] primes3 = intalg.primes_upto(100) self.assertEquals([6, 77, 8], primes3) # Because of the fake _prime_cache.
def testPollardPrime(self): random_obj = intalg.MiniIntRandom(42) for n in intalg.primes_upto(100000): b = intalg.pollard(n, random_obj) self.assertEquals(b, n)
def testBrentPrime(self): random_obj = intalg.MiniIntRandom(42) for n in intalg.primes_upto(100000): b = intalg.brent(n, random_obj) self.assertEquals(b, n)