Skip to content

Commit bae6ddc

Browse files
committed
is_prime() test coverage
looks like there is some test coverage variability from hypothesis so do few static examples
1 parent 95aa83f commit bae6ddc

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/ecdsa/test_numbertheory.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,38 @@ def st_comp_no_com_fac(draw):
207207
HYP_SLOW_SETTINGS["max_examples"] = 10
208208

209209

210+
class TestIsPrime(unittest.TestCase):
211+
def test_very_small_prime(self):
212+
assert is_prime(23)
213+
214+
def test_very_small_composite(self):
215+
assert not is_prime(22)
216+
217+
def test_small_prime(self):
218+
assert is_prime(123456791)
219+
220+
def test_special_composite(self):
221+
assert not is_prime(10261)
222+
223+
def test_medium_prime_1(self):
224+
# nextPrime[2^256]
225+
assert is_prime(2 ** 256 + 0x129)
226+
227+
def test_medium_prime_2(self):
228+
# nextPrime(2^256+0x129)
229+
assert is_prime(2 ** 256 + 0x12D)
230+
231+
def test_medium_trivial_composite(self):
232+
assert not is_prime(2 ** 256 + 0x130)
233+
234+
def test_medium_non_trivial_composite(self):
235+
assert not is_prime(2 ** 256 + 0x12F)
236+
237+
def test_large_prime(self):
238+
# nextPrime[2^2048]
239+
assert is_prime(2 ** 2048 + 0x3D5)
240+
241+
210242
class TestNumbertheory(unittest.TestCase):
211243
def test_gcd(self):
212244
assert gcd(3 * 5 * 7, 3 * 5 * 11, 3 * 5 * 13) == 3 * 5

0 commit comments

Comments
 (0)