|
1 | 1 | import unittest
|
2 | 2 | import random
|
| 3 | +from hypothesis import given, settings |
| 4 | +import hypothesis.strategies as st |
3 | 5 | from math import sqrt
|
4 | 6 | from operator import mul
|
5 | 7 | from primes import *
|
@@ -143,46 +145,10 @@ def testNPrimes5(self):
|
143 | 145 | def testNPrimes100(self):
|
144 | 146 | self.assertEqual(n_primes(100), primes_up_to(542))
|
145 | 147 |
|
146 |
| - def testNPrimes500(self): |
147 |
| - for i in range(500): |
148 |
| - with self.subTest(i=i): |
149 |
| - p = primes_up_to(i) |
150 |
| - self.assertEqual(n_primes(len(p)), p) |
151 |
| - |
152 |
| - def testNPrimes1000(self): |
153 |
| - for i in range(1000): |
154 |
| - with self.subTest(i=i): |
155 |
| - self.assertEqual(len(n_primes(i)), i) |
156 |
| - |
157 |
| - def testNPrimes10000(self): |
158 |
| - for i in range(10000, 10050): |
159 |
| - with self.subTest(i=i): |
160 |
| - self.assertEqual(len(n_primes(i)), i) |
161 |
| - |
162 |
| - def testNPrimes16000(self): |
163 |
| - for i in range(16000, 16005): |
164 |
| - with self.subTest(i=i): |
165 |
| - self.assertEqual(len(n_primes(i)), i) |
166 |
| - |
167 |
| - def testNPrimes40000(self): |
168 |
| - for i in range(40000, 40005): |
169 |
| - with self.subTest(i=i): |
170 |
| - self.assertEqual(len(n_primes(i)), i) |
171 |
| - |
172 |
| - def testNPrimes180000(self): |
173 |
| - for i in range(180000, 180005): |
174 |
| - with self.subTest(i=i): |
175 |
| - self.assertEqual(len(n_primes(i)), i) |
176 |
| - |
177 |
| - def testNPrimes700000(self): |
178 |
| - for i in range(700000, 700005): |
179 |
| - with self.subTest(i=i): |
180 |
| - self.assertEqual(len(n_primes(i)), i) |
181 |
| - |
182 |
| - def testNPrimes8010000(self): |
183 |
| - for i in range(8010000, 8010002): |
184 |
| - with self.subTest(i=i): |
185 |
| - self.assertEqual(len(n_primes(i)), i) |
| 148 | + @given(st.integers(min_value=0, max_value=100_000)) |
| 149 | + @settings(max_examples=20) |
| 150 | + def testNPrimes(self, i): |
| 151 | + self.assertEqual(len(n_primes(i)), i) |
186 | 152 |
|
187 | 153 | class TestNthPrime(unittest.TestCase):
|
188 | 154 | def testNthPrime1000(self):
|
|
0 commit comments