Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Hypothesis for n_primes tests (#44) #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
- python: nightly
install:
- pip install mypy
- pip install hypothesis
- pip install coverage
- pip install pylint
script:
Expand Down
46 changes: 6 additions & 40 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import unittest
import random
from hypothesis import given, settings
import hypothesis.strategies as st
from math import sqrt
from operator import mul
from primes import *
Expand Down Expand Up @@ -143,46 +145,10 @@ def testNPrimes5(self):
def testNPrimes100(self):
self.assertEqual(n_primes(100), primes_up_to(542))

def testNPrimes500(self):
for i in range(500):
with self.subTest(i=i):
p = primes_up_to(i)
self.assertEqual(n_primes(len(p)), p)

def testNPrimes1000(self):
for i in range(1000):
with self.subTest(i=i):
self.assertEqual(len(n_primes(i)), i)

def testNPrimes10000(self):
for i in range(10000, 10050):
with self.subTest(i=i):
self.assertEqual(len(n_primes(i)), i)

def testNPrimes16000(self):
for i in range(16000, 16005):
with self.subTest(i=i):
self.assertEqual(len(n_primes(i)), i)

def testNPrimes40000(self):
for i in range(40000, 40005):
with self.subTest(i=i):
self.assertEqual(len(n_primes(i)), i)

def testNPrimes180000(self):
for i in range(180000, 180005):
with self.subTest(i=i):
self.assertEqual(len(n_primes(i)), i)

def testNPrimes700000(self):
for i in range(700000, 700005):
with self.subTest(i=i):
self.assertEqual(len(n_primes(i)), i)

def testNPrimes8010000(self):
for i in range(8010000, 8010002):
with self.subTest(i=i):
self.assertEqual(len(n_primes(i)), i)
@given(st.integers(min_value=0, max_value=1_000_000))
@settings(max_examples=20)
def testNPrimes(self, i):
self.assertEqual(len(n_primes(i)), i)

class TestNthPrime(unittest.TestCase):
def testNthPrime1000(self):
Expand Down