Skip to content

Commit a79281d

Browse files
committed
more test coverage for numbertheory module
ensure that the test coverage doesn't fluctuate with hypothesis choices
1 parent b6d4138 commit a79281d

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/ecdsa/test_numbertheory.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,32 @@ def test_square_root_mod_prime_for_small_primes(prime):
8282
square_root_mod_prime(nonsquare, prime)
8383

8484

85+
def test_square_root_mod_prime_for_2():
86+
a = square_root_mod_prime(1, 2)
87+
assert a == 1
88+
89+
90+
def test_square_root_mod_prime_for_small_prime():
91+
root = square_root_mod_prime(98 ** 2 % 101, 101)
92+
assert root * root % 101 == 9
93+
94+
95+
def test_square_root_mod_prime_for_p_congruent_5():
96+
p = 13
97+
assert p % 8 == 5
98+
99+
root = square_root_mod_prime(3, p)
100+
assert root * root % p == 3
101+
102+
103+
def test_square_root_mod_prime_for_p_congruent_5_large_d():
104+
p = 29
105+
assert p % 8 == 5
106+
107+
root = square_root_mod_prime(4, p)
108+
assert root * root % p == 4
109+
110+
85111
@st.composite
86112
def st_two_nums_rel_prime(draw):
87113
# 521-bit is the biggest curve we operate on, use 1024 for a bit
@@ -324,6 +350,32 @@ def test_factorization(self, num):
324350
mult *= i[0] ** i[1]
325351
assert mult == num
326352

353+
def test_factorisation_smallprimes(self):
354+
exp = 101 * 103
355+
assert 101 in smallprimes
356+
assert 103 in smallprimes
357+
factors = factorization(exp)
358+
mult = 1
359+
for i in factors:
360+
mult *= i[0] ** i[1]
361+
assert mult == exp
362+
363+
def test_factorisation_not_smallprimes(self):
364+
exp = 1231 * 1237
365+
assert 1231 not in smallprimes
366+
assert 1237 not in smallprimes
367+
factors = factorization(exp)
368+
mult = 1
369+
for i in factors:
370+
mult *= i[0] ** i[1]
371+
assert mult == exp
372+
373+
def test_jacobi_with_zero(self):
374+
assert jacobi(0, 3) == 0
375+
376+
def test_jacobi_with_one(self):
377+
assert jacobi(1, 3) == 1
378+
327379
@settings(**HYP_SETTINGS)
328380
@given(st.integers(min_value=3, max_value=1000).filter(lambda x: x % 2))
329381
def test_jacobi(self, mod):

0 commit comments

Comments
 (0)