@@ -68,6 +68,7 @@ def test_next_prime_with_nums_less_2(val):
6868 assert next_prime (val ) == 2
6969
7070
71+ @pytest .mark .slow
7172@pytest .mark .parametrize ("prime" , smallprimes )
7273def test_square_root_mod_prime_for_small_primes (prime ):
7374 squares = set ()
@@ -85,6 +86,32 @@ def test_square_root_mod_prime_for_small_primes(prime):
8586 square_root_mod_prime (nonsquare , prime )
8687
8788
89+ def test_square_root_mod_prime_for_2 ():
90+ a = square_root_mod_prime (1 , 2 )
91+ assert a == 1
92+
93+
94+ def test_square_root_mod_prime_for_small_prime ():
95+ root = square_root_mod_prime (98 ** 2 % 101 , 101 )
96+ assert root * root % 101 == 9
97+
98+
99+ def test_square_root_mod_prime_for_p_congruent_5 ():
100+ p = 13
101+ assert p % 8 == 5
102+
103+ root = square_root_mod_prime (3 , p )
104+ assert root * root % p == 3
105+
106+
107+ def test_square_root_mod_prime_for_p_congruent_5_large_d ():
108+ p = 29
109+ assert p % 8 == 5
110+
111+ root = square_root_mod_prime (4 , p )
112+ assert root * root % p == 4
113+
114+
88115@st .composite
89116def st_two_nums_rel_prime (draw ):
90117 # 521-bit is the biggest curve we operate on, use 1024 for a bit
@@ -209,7 +236,7 @@ def st_comp_no_com_fac(draw):
209236
210237HYP_SLOW_SETTINGS = dict (HYP_SETTINGS )
211238if "--fast" in sys .argv :
212- HYP_SLOW_SETTINGS ["max_examples" ] = 2
239+ HYP_SLOW_SETTINGS ["max_examples" ] = 1
213240else :
214241 HYP_SLOW_SETTINGS ["max_examples" ] = 20
215242
@@ -292,7 +319,8 @@ def test_square_root_mod_prime(self, vals):
292319 calc = square_root_mod_prime (square , prime )
293320 assert calc * calc % prime == square
294321
295- @settings (** HYP_SETTINGS )
322+ @pytest .mark .slow
323+ @settings (** HYP_SLOW_SETTINGS )
296324 @given (st .integers (min_value = 1 , max_value = 10 ** 12 ))
297325 @example (265399 * 1526929 )
298326 @example (373297 ** 2 * 553991 )
@@ -303,7 +331,33 @@ def test_factorization(self, num):
303331 mult *= i [0 ] ** i [1 ]
304332 assert mult == num
305333
306- @settings (** HYP_SETTINGS )
334+ def test_factorisation_smallprimes (self ):
335+ exp = 101 * 103
336+ assert 101 in smallprimes
337+ assert 103 in smallprimes
338+ factors = factorization (exp )
339+ mult = 1
340+ for i in factors :
341+ mult *= i [0 ] ** i [1 ]
342+ assert mult == exp
343+
344+ def test_factorisation_not_smallprimes (self ):
345+ exp = 1231 * 1237
346+ assert 1231 not in smallprimes
347+ assert 1237 not in smallprimes
348+ factors = factorization (exp )
349+ mult = 1
350+ for i in factors :
351+ mult *= i [0 ] ** i [1 ]
352+ assert mult == exp
353+
354+ def test_jacobi_with_zero (self ):
355+ assert jacobi (0 , 3 ) == 0
356+
357+ def test_jacobi_with_one (self ):
358+ assert jacobi (1 , 3 ) == 1
359+
360+ @settings (** HYP_SLOW_SETTINGS )
307361 @given (st .integers (min_value = 3 , max_value = 1000 ).filter (lambda x : x % 2 ))
308362 def test_jacobi (self , mod ):
309363 if is_prime (mod ):
@@ -322,7 +376,7 @@ def test_jacobi(self, mod):
322376 c *= jacobi (a , i [0 ]) ** i [1 ]
323377 assert c == jacobi (a , mod )
324378
325- @settings (** HYP_SETTINGS )
379+ @settings (** HYP_SLOW_SETTINGS )
326380 @given (st_two_nums_rel_prime ())
327381 def test_inverse_mod (self , nums ):
328382 num , mod = nums
0 commit comments