Advertisement
romeq8787

Untitled

Sep 22nd, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import unittest
  2.  
  3. def primes(max_n):
  4.     found = [2, 3]
  5.     for candidate in xrange(4, max_n + 1):
  6.         for prime in found:
  7.             if not candidate % prime:
  8.                 import pdb; pdb.set_trace()
  9.                 break
  10.         else:
  11.             found.append(candidate)
  12.     return found
  13.  
  14. class PrimeTest(unittest.TestCase):
  15.  
  16.     def test_primes(self):
  17.         actual = primes(20)
  18.         self.assertEqual(actual, [2, 3, 5, 7, 11, 13, 17, 19])
  19.  
  20. if __name__ == '__main__':
  21.     unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement