Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pruebas unitarias para find_primes.py (https://gist.github.com/1623748)
#!/usr/bin/python
# -*- coding: utf-8 -*-
from itertools import izip
from unittest import main, TestCase
from find_primes import allPrimes, isPrime, findNthPrime
class TestPrimes(TestCase):
def verifyIsPrime(self, number, outcome):
result = isPrime(number)
message = '%d should%s be prime, but the test yielded %r' % (
number, (not outcome and ' not' or ''), result)
self.assertEquals(outcome, result, message)
def test_is_prime_00_to_09(self):
expected = {
0: False, 1: False, 2: True, 3: True, 4: False,
5: True, 6: False, 7: True, 8: False, 9: False,
}
for (number, result) in expected.iteritems():
self.verifyIsPrime(number, result)
def test_primes_less_than_100(self):
primes_less_than_100 = (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)
for e, a in izip(primes_less_than_100, allPrimes()):
self.assertEquals(e, a)
def test_find_nth_prime(self):
self.assertEquals(104743, findNthPrime(10001))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment