diff options
Diffstat (limited to 'tests/test_prime.py')
-rw-r--r-- | tests/test_prime.py | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/tests/test_prime.py b/tests/test_prime.py index 5577f67..42d8af1 100644 --- a/tests/test_prime.py +++ b/tests/test_prime.py @@ -35,7 +35,7 @@ class PrimeTest(unittest.TestCase): # Test some slightly larger numbers self.assertEqual( [907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997], - [x for x in range(901, 1000) if rsa.prime.is_prime(x)] + [x for x in range(901, 1000) if rsa.prime.is_prime(x)], ) # Test around the 50th millionth known prime. @@ -62,13 +62,23 @@ class PrimeTest(unittest.TestCase): self.assertEqual([], randints) # 'Exit inner loop and continue with next witness' - randints.extend([ - 2119139098, # causes 'Exit inner loop and continue with next witness' - # the next witnesses for the above case: - 3051067716, 3603501763, 3230895847, 3687808133, 3760099987, 4026931495, 3022471882, - ]) - self.assertEqual(True, rsa.prime.miller_rabin_primality_testing(2211417913, - len(randints))) + randints.extend( + [ + 2119139098, # causes 'Exit inner loop and continue with next witness' + # the next witnesses for the above case: + 3051067716, + 3603501763, + 3230895847, + 3687808133, + 3760099987, + 4026931495, + 3022471882, + ] + ) + self.assertEqual( + True, + rsa.prime.miller_rabin_primality_testing(2211417913, len(randints)), + ) self.assertEqual([], randints) finally: rsa.randnum.randint = orig_randint @@ -84,22 +94,38 @@ class PrimeTest(unittest.TestCase): # List of known Mersenne exponents. known_mersenne_exponents = [ - 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, - 2203, 2281, 4423, + 2, + 3, + 5, + 7, + 13, + 17, + 19, + 31, + 61, + 89, + 107, + 127, + 521, + 607, + 1279, + 2203, + 2281, + 4423, ] # Test Mersenne primes. for exp in known_mersenne_exponents: - self.assertTrue(rsa.prime.is_prime(2**exp - 1)) + self.assertTrue(rsa.prime.is_prime(2 ** exp - 1)) def test_get_primality_testing_rounds(self): """Test round calculation for primality testing.""" - self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 63), 10) + self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 63), 10) self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 127), 10) self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 255), 10) - self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 511), 7) - self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 767), 7) + self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 511), 7) + self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 767), 7) self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 1023), 4) self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 1279), 4) self.assertEqual(rsa.prime.get_primality_testing_rounds(1 << 1535), 3) |