Permalink
Browse files

prime generator assertion patch

  • Loading branch information...
1 parent 5eab5ef commit 766b0441cfd1a3c47a7e5669b93c6dbb3331ddbb @jabbalaci committed Jul 3, 2012
Showing with 29 additions and 13 deletions.
  1. +2 −2 jabbapylib/config.py
  2. +15 −6 jabbapylib/math/euler.py
  3. +7 −0 tests/math/test_euler.py
  4. +5 −5 tests/math/test_pi.py
View
@@ -7,8 +7,8 @@
"""
__author__ = "Laszlo Szathmary (jabba.laci@gmail.com)"
-__version__ = "0.2.9"
-__date__ = "20120702"
+__version__ = "0.3.0"
+__date__ = "20120703"
__copyright__ = "Copyright (c) 2011-2012 Laszlo Szathmary"
__license__ = "GPL"
View
@@ -158,6 +158,8 @@ def get_primes_between(start, stop):
with the Miller-Rabin test (is_prime_mr()). Slower but more
reliable than this one for very large numbers.
"""
+ assert start >= 0 and stop <= 4294967295
+ #
li = []
proc = Popen([cfg.PRIMES, str(start), str(stop)],stdout=PIPE)
while True:
@@ -171,7 +173,8 @@ def get_primes_between(start, stop):
def gen_primes():
- """It's a generator, so use it like any other.
+ """
+ It's a generator, so use it like any other.
primes = gen_primes()
for p in primes:
@@ -199,7 +202,9 @@ def gen_primes():
def prime_divisors(n):
- """Prime divisors."""
+ """
+ Prime divisors.
+ """
li = []
np = gen_primes()
@@ -213,17 +218,21 @@ def prime_divisors(n):
def is_palindrome(s):
- """Decide if a string is a palindrome or not.
+ """
+ Decide if a string is a palindrome or not.
- Palindrome: you get the same string reading backwards."""
+ Palindrome: you get the same string reading backwards.
+ """
return s == s[::-1]
def inc_avg(li):
- """Calculate the average incrementally.
+ """
+ Calculate the average incrementally.
Input: a list.
Output: average of the list.
- See http://ubuntuincident.wordpress.com/2012/04/25/calculating-the-average-incrementally/ ."""
+ See http://ubuntuincident.wordpress.com/2012/04/25/calculating-the-average-incrementally/ .
+ """
left = 0
right = len(li)-1
View
@@ -1,3 +1,4 @@
+import pytest
from jabbapylib import config as cfg
from jabbapylib.filesystem import fs
from jabbapylib.math import euler
@@ -33,6 +34,12 @@ def test_prime_generator():
def test_get_primes_between():
li = [2, 3, 5, 7, 11, 13, 17, 19]
assert euler.get_primes_between(1, 23) == li
+ #
+ with pytest.raises(AssertionError):
+ euler.get_primes_between(-1, 23)
+ #
+ with pytest.raises(AssertionError):
+ euler.get_primes_between(4294967290, 4294967296)
def test_gen_primes():
"""See if it generates correctly the primes below 1000."""
View
@@ -8,8 +8,8 @@ def test_get_digits_of():
assert digits[-10:] == '2164201989'
os.unlink(pi.TMP_DIR + '/' + pi.PI3)
-def test_three_parts():
- one = pi.get_digits_of(pi.PI3)
- two = pi.get_digits(1000)
- three = pi.get_pi(1000)
- assert one == two == three
+#def test_three_parts():
+# one = pi.get_digits_of(pi.PI3)
+# two = pi.get_digits(1000)
+# three = pi.get_pi(1000)
+# assert one == two == three

0 comments on commit 766b044

Please sign in to comment.