Question: For each function in this program: (1) Check that the function works as described per its docstring specification (type contract, briefdescription, examples of use).(2) Fix
For each function in this program: (1) Check that the function works as described per its docstring specification (type contract, briefdescription, examples of use).(2) Fix any bugs that you find.Document your changes.(3) Generate at least three test cases for each function (beyond the simple examples of use that aregiven). Be sure to include normal input and boundary, or edge, input, e.g., 0, 1, empty strings orlists, etc. Vary the examples of normal input and include examples to generate different results.Add the new test cases to the function docstring and comment on what they are testing.NOTE: Functions do NOT need to check for illegal argument values; arguments are assumed to be as specified in the type contract and brief description for each function. (4) Fix any additional bugs that you find. (NOTE: All of the functions have one or more bugs, notall of which are apparent from the original docstring examples.) Document your changes.(5) Test your changes, fix any additional bugs, and repeat until the code is stable.NOTE: Do not rewrite function code. Change the code just enough to fix the bug(s) in the codeas written.
For example, given:
def myCt(s, c):
'''(str) -> int
Count number of occurrences of c in string s.Return the count (zero is c does not occur in sor s is empty string).
>>> myCt('abbc', 'b')
2'''
for ch in s:
if ch == c:
ccount += 1
return ccount
The (partially)correctedcode should look something like this:
import doctest
def myCt(s, c):
'''(str) -> int
Count number of occurrences of c in string s.Return the count (zero is c does not occur in sor s is empty string).
>>> myCt('abbc', 'b')
2
>>> myCt('', 'a') # edge -empty string
0
[more test cases as needed]'''
ccount= 0 # initialize ccount
for ch in s:
if ch == c:
ccount += 1
return ccount
print(doctest.testmod())
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
