Skip to content

Commit

Permalink
Fixes incorrect values in prev_prime()
Browse files Browse the repository at this point in the history
Fixes #529
  • Loading branch information
mhostetter committed Dec 1, 2023
1 parent 4984e40 commit 852e92f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/galois/_prime.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def prev_prime(n: int) -> int:
while True:
for shift in shifts:
i = base + shift # May be bigger than n
if i >= n:
if i > n:
continue
if is_prime(i):
return i
Expand Down
13 changes: 12 additions & 1 deletion tests/test_primes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ def test_prev_prime(prev_prime):
assert galois.prev_prime(x) == z


def test_prev_prime_large():
"""
https://github.com/mhostetter/galois/issues/529
"""
assert galois.prev_prime(100000034) == 100000007
assert galois.prev_prime(100000035) == 100000007
assert galois.prev_prime(100000036) == 100000007
assert galois.prev_prime(100000037) == 100000037
assert galois.prev_prime(100000038) == 100000037


def test_next_prime_exceptions():
with pytest.raises(TypeError):
galois.next_prime(20.0)
Expand All @@ -58,7 +69,7 @@ def test_next_prime(next_prime):
assert galois.next_prime(x) == z


def test_next_prime_bug_528():
def test_next_prime_large():
"""
https://github.com/mhostetter/galois/issues/528
"""
Expand Down

0 comments on commit 852e92f

Please sign in to comment.