def test_primality_test_6(self): certainty = 1000 n = 13790129586234798731 expected_is_prime = False is_prime = primality_test(n, certainty) print("Expected to be " + str(expected_is_prime) + " | Was actually " + str(is_prime)) self.assertEqual(expected_is_prime, is_prime)
def test_primality_test_7(self): certainty = 1000 n = 99999999999991 expected_is_prime = False is_prime = primality_test(n, certainty) print("Expected to be " + str(expected_is_prime) + " | Was actually " + str(is_prime)) self.assertEqual(expected_is_prime, is_prime)
def test_primality_test_5(self): certainty = 1000 n = 28116440335967 expected_is_prime = True is_prime = primality_test(n, certainty) print("Expected to be " + str(expected_is_prime) + " | Was actually " + str(is_prime)) self.assertEqual(expected_is_prime, is_prime)
def test_primality_test_1(self): print("\n\nRunning test for src module: primality_test") certainty = 1000 n = 13 expected_is_prime = True is_prime = primality_test(n, certainty) print("Expected to be " + str(expected_is_prime) + " | Was actually " + str(is_prime)) self.assertEqual(expected_is_prime, is_prime)
def random_prime(bits): max_int = "" for i in range(0,bits): max_int += "1" max = int(max_int, 2) rand = random.randint(1,max) if rand % 2 == 0: rand+=1 while not primality_test(rand): rand = (rand + 2) % max return rand
def prime_number_theorem(limit): number_of_primes = 0 i_div_ln_i = 0 ratio = 0 for i in range(2, limit): if i % 10000 == 0: ratio = number_of_primes / i_div_ln_i print("Ratio : " + str(ratio)) if primality_test(i, 1000): number_of_primes += 1 i_div_ln_i = i / math.log( i) # When math.log has one arg, it does the natural log, ln
def test_random_prime_4(self): rand_prime = random_prime(512) self.assertEqual(primality_test(rand_prime), True)
def test_random_prime_1(self): print("\n\nRunning test for src module: random_prime") rand_prime = random_prime(64) self.assertEqual(primality_test(rand_prime), True)