Question: For each function listed below ( invert , favorite _ color, count, alphabetize, update _ attendance ) , you are to define at least 3
For each function listed below invert favoritecolor, count, alphabetize, updateattendance you are to define at least x unit test functions. Remember that a unit test function starts with test
The unit tests should consist of:
Two use cases: expected use cases of a function
One edge case: unexpected use cases of a function
Include descriptive function names and docstrings, so that it captures what is being tested.
def invertdictionary:
Invert Function."""
inverteddict
for key, value in dictionary.items:
if value in inverteddict:
raise KeyErrorDuplicate value encountered while inverting dictionary"
inverteddictvalue key
return inverteddict
def favoritecolorcolors:
Favorite Color Function."""
colorcount
for color in colors.values:
colorcountcolor colorcount.getcolor
maxcount maxcolorcount.values
for name, color in colors.items:
if colorcountcolor maxcount:
return color
def countlst:
Count Function."""
countdict
for item in lst:
if item in countdict:
countdictitem
else:
countdictitem
return countdict
def alphabetizerwords:
Alphabetizer Function."""
alphabetdict
for word in words:
firstletter wordlower
if firstletter in alphabetdict:
alphabetdictfirstletterappendword
else:
alphabetdictfirstletterword
return alphabetdict
def updateattendanceattendancelog day, student:
Update Attendance Function."""
if day in attendancelog:
attendancelogdayappendstudent
else:
attendancelogdaystudent
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
