diff --git a/src/galois/_prime.py b/src/galois/_prime.py index 6c007115b..cb919b698 100644 --- a/src/galois/_prime.py +++ b/src/galois/_prime.py @@ -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 diff --git a/tests/test_primes.py b/tests/test_primes.py index fc45b7ced..d86990c36 100644 --- a/tests/test_primes.py +++ b/tests/test_primes.py @@ -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) @@ -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 """