Tetsuya Morimoto avatar Tetsuya Morimoto committed 521b736

added the tox test sample

Comments (0)

Files changed (4)

+.installed.cfg
+.pyc
+.swp
+.tox
+build
+develop-eggs
+dist
+eggs
+parts
+.*.egg-info

tox_test/setup.py

+# -*- coding: utf-8 -*-
+
+from setuptools import setup
+
+setup(
+    name="mytestpackage",
+    version="0.1.0",
+    description="just for tox testing package",
+    author="Tetsuya Morimoto",
+    url="http://bitbucket.org/t2y/misc/",
+    license="Apache License 2.0",
+    platforms=['unix', 'linux', 'osx'],
+    tests_require=["tox", "pytest"],
+)

tox_test/src/eratosthenes.py

+# -*- coding: utf-8 -*-
+
+def sieve_of_eratosthenes(max_num):
+    """
+    >>> list(sieve_of_eratosthenes(-1))
+    []
+    >>> list(sieve_of_eratosthenes(1))
+    []
+    >>> list(sieve_of_eratosthenes(3))
+    [2, 3]
+    >>> list(sieve_of_eratosthenes(30))
+    [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
+    """
+    search_list = {}
+    _max_num = max_num + 1
+    for num in range(2, _max_num):
+        if search_list.get(num) is None:
+            for i in range(2 * num, _max_num, num):
+                search_list[i] = False
+            yield num
+        if pow(num, 2) > _max_num:
+            for i in range(num + 1, _max_num):
+                if search_list.get(i) is None:
+                    yield i
+            break
+
+def is_prime(num):
+    """
+    >>> is_prime(3)
+    True
+    >>> is_prime(4)
+    False
+    """
+    return num in sieve_of_eratosthenes(num)

tox_test/src/tests/test_eratosthenes.py

+# -*- coding: utf-8 -*-
+
+import pytest
+from eratosthenes import sieve_of_eratosthenes, is_prime
+
+PRIMES = [
+    2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
+    59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
+    131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
+    211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283,
+    293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383,
+    389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467,
+    479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577,
+    587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661,
+    673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769,
+    773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877,
+    881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
+    991, 997,
+]
+
+@pytest.mark.parametrize(("max_num", "expected"), [
+    (10, 4),
+    (30, 10),
+    (PRIMES[-1], len(PRIMES)),
+])
+def test_sieve_of_eratosthenes(max_num, expected):
+    assert expected == len(list(sieve_of_eratosthenes(max_num)))
+
+@pytest.mark.parametrize("num", PRIMES)
+def test_is_prime(num):
+    assert is_prime(num)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.