def is_uniform(lower=2, upper=1000): """ For all the fonction of nprime, check if they generate the same prime numbers as the is_prime function Returns True or the results if False """ results = {'ref2': [], 'fermat': [], 'miller_rabin': []} ref1 = p.find_primes(lower, upper) ref2 = p.generate_primes(upper) fermat = p.find_primes(lower, upper, p.fermat) miller_rabin = p.find_primes(lower, upper, p.miller_rabin) # Testing if we have the same primes from ref1 in all other functions for n in ref1: if n not in ref2: results['ref2'].append(n) if n not in fermat: results['fermat'].append(n) if n not in miller_rabin: results['miller_rabin'].append(n) # Making sure there's more detected primes than in ref1 for key in results: results[key].append(len(results[key])) if results[key] != [0]: return results return True
def main(): """ example of the prime function and custom tests """ # Demo of the Primary testing functions print(is_prime(7)) print(p.fermat(7)) print(p.miller_rabin(7)) # Demo of the Prime generating functions print(p.generate_primes(7)) print(p.find_primes(2, 7, p.fermat)) # Demo of the custom_test functions print(ut.custom_test(p.is_prime)) # Demo of Graphical Prime functions sacks_plot() ulam_plot()
def test_001_is_there_2_in_list_of_first_prime(self): """ there should only be 2 in the list, if limit is set to 2 """ self.assertEquals([2], generate_primes(2))
def test_003_are_first_prime_all_generated(self): output = generate_primes(70) for n in range(0, len(output)): self.assertEquals(FIRST_PRIMES[n], output[n], msg='Missing - {} - in generated prime list '.format(FIRST_PRIMES[n]))
def test_002_inferior_to_two_return_nothing(self): """ No prime should be generated if upper is inferior to 2""" self.assertEquals([], generate_primes(1))