-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathP71_PythonUnittest.py
44 lines (35 loc) · 1.32 KB
/
P71_PythonUnittest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Author: OMKAR PATHAK
# This module helps to build the testcases for a particular program to test its integrity and overall execution
import unittest
def checkPrime(number):
'''This function checks if the number is a prime number'''
if number == 2:
return True
if number > 2:
for i in range(2, number):
if number % i == 0:
return False
break
else:
return True
break
else:
return False
# Class for providing test cases
class CheckPrime(unittest.TestCase):
def test_checkPrime(self):
self.assertEqual(checkPrime(3), True) # Check if the function returns the value specified in the second argument
def test_checkPrime2(self):
self.assertTrue(checkPrime(5)) # Check if the function returns True
self.assertFalse(checkPrime(4)) # Check if the function returns False
def test_checkPrime3(self):
# Check that providing a string input produces an error
with self.assertRaises(TypeError):
checkPrime('1')
if __name__ == '__main__':
unittest.main()
# OUTPUT:
# ----------------------------------------------------------------------
# Ran 3 tests in 0.000s
#
# OK