- Notifications
You must be signed in to change notification settings - Fork 638
Expand file tree
/
Copy pathP71_PythonUnittest.py
More file actions
Latest commit
44 lines (35 loc) · 1.27 KB
/
Copy pathP71_PythonUnittest.py
File metadata and controls
44 lines (35 loc) · 1.27 KB
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
importunittest
defcheckPrime(number):
'''This function checks if the number is a prime number'''
ifnumber==2:
returnTrue
ifnumber>2:
foriinrange(2, number):
ifnumber%i==0:
returnFalse
break
else:
returnTrue
break
else:
returnFalse
# Class for providing test cases
classCheckPrime(unittest.TestCase):
deftest_checkPrime(self):
self.assertEqual(checkPrime(3), True) # Check if the function returns the value specified in the second argument
deftest_checkPrime2(self):
self.assertTrue(checkPrime(5)) # Check if the function returns True
self.assertFalse(checkPrime(4)) # Check if the function returns False
deftest_checkPrime3(self):
# Check that providing a string input produces an error
withself.assertRaises(TypeError):
checkPrime('1')
if__name__=='__main__':
unittest.main()
# OUTPUT:
# ----------------------------------------------------------------------
# Ran 3 tests in 0.000s
#
# OK