Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
 def test_006_are_primes_found_in_interval(self):
     """ Test that primes are found in a different interval """
     prime_list_1000_to_1100 = [
         1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063,
         1069, 1087, 1091, 1093, 1097
     ]
     self.assertTrue(find_primes(1000, 1100) == prime_list_1000_to_1100)
Ejemplo n.º 3
0
 def test_005_are_first_prime_all_discovered(self):
     """ Test that first primes are found """
     output = find_primes(2, 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]))
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
 def test_007_find_no_primes_when_no_primes(self):
     """ Test that it founds no primes in an interval with no primes """
     self.assertTrue(find_primes(370270, 370370) == [])