Skip to content

Commit

Permalink
Correction of math.prime_generator in case of p_min being an even num…
Browse files Browse the repository at this point in the history
…ber greater than two
  • Loading branch information
julienc91 committed May 11, 2016
1 parent 521fe2d commit 3a421bb
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 1.2.1 - 2016-05-11

The `math.prime_generator` was not working correctly if the parameter `p_min` was an even integer greater than two.

## 1.2 - 2016-04-27

New packages `dicts` and `dates`. `dates` provides an easy to use timer class to mesure the execution time
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -8,8 +8,8 @@ utools
A set of useful functions to use for various purposes in any Python project.

* Author: Julien CHAUMONT (https://julienc.io)
* Version: 1.2
* Date: 2016-04-28
* Version: 1.2.1
* Date: 2016-05-11
* Licence: MIT
* Url: http://github.com/julienc91/utools

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -55,9 +55,9 @@
# built documents.
#
# The short X.Y version.
version = '1.2'
version = '1.2.1'
# The full version, including alpha/beta/rc tags.
release = '1.2'
release = '1.2.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -4,7 +4,7 @@

setup(
name="utools",
version="1.2",
version="1.2.1",
author="Julien Chaumont",
author_email="utools@julienc.io",
description="A set of useful functions to use for various purposes in any Python project",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_math.py
Expand Up @@ -133,7 +133,7 @@ def test_prime_generator_with_bad_parameters(p_min, p_max, expected_exception):

# we want to test that the two prime generators functions return the same primes
@pytest.mark.parametrize("p_min, p_max,", [
(2, 4), (4, 2), (3, None), (2, None), (-1, 21)
(2, 4), (4, 2), (3, None), (2, None), (-1, 21), (20, 101)
])
def test_prime_generator_and_sieve_of_eratosthenes(p_min, p_max):
count_max = 1000
Expand Down
2 changes: 1 addition & 1 deletion utools/__init__.py
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = "1.2"
__version__ = "1.2.1"
3 changes: 3 additions & 0 deletions utools/math.py
Expand Up @@ -106,6 +106,9 @@ def prime_generator(p_min=2, p_max=None):
q = max(p_min, 3)
if p_min <= 2 and (p_max is None or p_max >= 2):
yield 2 # outside the while block to make the double increment optimization work
if p_min % 2 == 0:
p_min += 1

while p_max is None or q <= p_max:
if is_prime(q):
yield q
Expand Down

0 comments on commit 3a421bb

Please sign in to comment.