File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Author: OMKAR PATHAK
2+
3+ # This module helps to build the testcases for a particular program to test its integrity and overall execution
4+
5+ import unittest
6+
7+ def checkPrime (number ):
8+ '''This function checks if the number is a prime number'''
9+ if number == 2 :
10+ return True
11+ if number > 2 :
12+ for i in range (2 , number ):
13+ if number % i == 0 :
14+ return False
15+ break
16+ else :
17+ return True
18+ break
19+ else :
20+ return False
21+
22+ # Class for providing test cases
23+ class CheckPrime (unittest .TestCase ):
24+
25+ def test_checkPrime (self ):
26+ self .assertEqual (checkPrime (3 ), True ) # Check if the function returns the value specified in the second argument
27+
28+ def test_checkPrime2 (self ):
29+ self .assertTrue (checkPrime (5 )) # Check if the function returns True
30+ self .assertFalse (checkPrime (4 )) # Check if the function returns False
31+
32+ def test_checkPrime3 (self ):
33+ # Check that providing a string input produces an error
34+ with self .assertRaises (TypeError ):
35+ checkPrime ('1' )
36+
37+ if __name__ == '__main__' :
38+ unittest .main ()
39+
40+ # OUTPUT:
41+ # ----------------------------------------------------------------------
42+ # Ran 3 tests in 0.000s
43+ #
44+ # OK
You can’t perform that action at this time.
0 commit comments