def test_primes(): ''' test if the eratosthenes function can return a list matches with expected one ''' primeList19 = [2, 3, 5, 7, 11, 13, 17] #expected prime list retList = primes.eratosthenes(19) print(retList) assert primeList19 == retList
def test_eratosthenes_last(): """Verify the largest prime number under 200. Note: The equality test for the assert here only works because the integers inside the list support exact equality. Question: What data structures work with this sort of test? """ assert primes.eratosthenes(200)[-1] == 199
def run(): found = set() primeset = set() for p in primes.eratosthenes(): primeset.add(p) if p <= 7: continue if set(truncations(p)).issubset(primeset): found.add(p) # the problems states there are only 11 such numbers if len(found) == 11: break print(sum(found))
def test_eratosthenes_number(): """Verify the number of primes less than 200. """ assert len(primes.eratosthenes(200)) == 46
def test_primes2(): result = primes.eratosthenes(50) correct = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] assert result == correct
def test_primes(): result = primes.eratosthenes(5) correct = [2, 3] assert result == correct
def test_primes(): assert primes.eratosthenes(5) == [2, 3] g = primes.gen_eratosthenes() assert [next(g) for _ in range(3)] == [2, 3, 5]
def run(): # all primes below a million primeset = set(itertools.takewhile(lambda i:i<1000000, primes.eratosthenes())) print(len([n for n in primeset if set(rotations(n)).issubset(primeset)]))
def test_primes1(): """test the first prime numbers smaller than 500""" result = primes.eratosthenes(500) correct = [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] assert result == correct
def test_primes2(): "test the last prime number below 1000" result = primes.eratosthenes(1000)[-1] assert result == 997
def test_primes(): """test the first 10 prime numbers""" result = primes.eratosthenes(30) correct = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] assert result == correct
def test_primes(): result = primes.eratosthenes(10) correct = [2, 3, 5, 7] assert result == correct
Question: What data structures work with this sort of test? """ assert primes.eratosthenes(200)[-1] == 199 def eratosthenes(n): """Verify the number of primes less than 200. """ primes = [] for primes in range(1,n): primes.append(i) for i in primes: for n in primes: if prime(n)// i= 0: primes.pop(n) assert len(primes.eratosthenes(200)) == 46 print primes return primes def gen_eratosthenes_last(): """Verify the largest prime number under 200. """ g = primes.gen_eratosthenes() p = next(g) p2 = next(g) while p2 < 200: p, p2 = p2, next(g) assert p == 199 def gen_eratosthenes(n): """Verify the number of primes less than 200.
def test_primes(): assert primes.eratosthenes(60) == [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 ] assert primes.eratosthenes(34) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
def test_primes(): #Tests eratosthenes for n = 23, 10, and 15 assert eratosthenes(23) == [2, 3, 5, 7, 11, 13, 17, 19] assert eratosthenes(10) == [2, 3, 5, 7] assert eratosthenes(15) == [2, 3, 5, 7, 11, 13]