Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
"""
THESE IS NO NEED TO EDIT THIS FILE
"""
import unittest
import uuid
import hashlib
#And our library
import FixMe
#Primes up to 100
PRIMELIST = [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]
class Test_Primes(unittest.TestCase):
def testUUID(self):
#Spin up that Random number generator seed.
theSeed = uuid.uuid1()
print(theSeed)
self.assertTrue(theSeed, "Random Number Init Fails")
def testValidity(self):
#Check the Validity of the file
with open("test_cases.py", "r") as fd:
data = fd.read()
theHash = hashlib.md5(data.encode()).hexdigest()
print(theHash)
self.assertTrue(theHash, "File Integrety Fails")
def testPrimes(self):
"""
Are Known Primes Prime
"""
primeList = [2,7,11,43,67]
out = [] #Juyst to get some output
for item in primeList:
isPrime = FixMe.isPrime(item)
if isPrime:
out.append(item)
self.assertTrue(isPrime, "{0} is Prime".format(item))
print ("Prime Values {0}".format(out))
def testNonPrimes(self):
"""
Are Known non primes matched
"""
primeList = [4,10,25,42]
out = [] #Juyst to get some output
for item in primeList:
isPrime = FixMe.isPrime(item)
if not isPrime:
out.append(item)
self.assertFalse(isPrime, "{0} is not Prime".format(item))
print ("Prime Values {0}".format(out))
def test_OneIsNotPrime(self):
"""
Test some corner cases.
One is not prime.
"""
onePrime = FixMe.isPrime(1)
self.assertFalse(onePrime, "1 Is not Prime. A number must be greater than 1 to be prime")
def test_TwoIsPrime(self):
"""
Test some corner cases.
Two is Prime
"""
#the only "Even" prime
twoPrime = FixMe.isPrime(2)
self.assertTrue(twoPrime, "2 Is Prime. (and the only Even Prime Number)")
def testPrimeList_Twenty(self):
"""
See if our function to find all primes up to a number works
"""
primesTo20 = FixMe.primeList(20)
self.assertEqual(primesTo20, [2,3,5,7,11,13,17,19], "List of primes generated is incorrect")
def testPrimeList_Hundred(self):
"""
Test if our list of the first 100 primes is correct
"""
output = FixMe.primeList(100)
self.assertEqual(output,PRIMELIST , "List of primes generated is incorrect")
def test_First10Primes(self):
"""
Can we get a list of the first 10 primes
"""
output = FixMe.getFirstNPrimes(10)
self.assertEqual(len(output), 10, "List shopuld return 10 Primes" )
self.assertEqual(output, PRIMELIST[:10], "First 10 primes are incorrect")