mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 18:33:58 -05:00
Added function to test if a number is prime
This commit is contained in:
@@ -42,6 +42,29 @@ class TestAlgorithms(unittest.TestCase):
|
||||
answer = Algorithms.getNumPrimes(numPrimes) #Get the answer from the function
|
||||
self.assertEqual(correctAnswer, answer, "getNumPrimes failed the first test")
|
||||
|
||||
#This function tests the isPrime function
|
||||
def testIsPrime(self):
|
||||
#Test 1
|
||||
num = 2
|
||||
correctAnswer = True
|
||||
answer = Algorithms.isPrime(num)
|
||||
self.assertEqual(correctAnswer, answer, "isPrime failed the first test")
|
||||
#Test 2
|
||||
num = 97
|
||||
correctAnswer = True
|
||||
answer = Algorithms.isPrime(num)
|
||||
self.assertEqual(correctAnswer, answer, "isPrime failed the second test")
|
||||
#Test 3
|
||||
num = 1000
|
||||
correctAnswer = False
|
||||
answer = Algorithms.isPrime(num)
|
||||
self.assertEqual(correctAnswer, answer, "isPrime failed the third test")
|
||||
#Test 4
|
||||
num = 1
|
||||
correctAnswer = False
|
||||
answer = Algorithms.isPrime(num)
|
||||
self.assertEqual(correctAnswer, answer, "isPrime failed the fourth test")
|
||||
|
||||
#This function tests the getFactors function
|
||||
def testGetFactors(self):
|
||||
#Test 1
|
||||
@@ -203,9 +226,9 @@ if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
"""Results:
|
||||
............
|
||||
.............
|
||||
----------------------------------------------------------------------
|
||||
Ran 12 tests in 0.002s
|
||||
Ran 13 tests in 0.002s
|
||||
|
||||
OK
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user