Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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, favorite_color, count, alphabetize, update_attendance), you are to define at least 3x unit test functions. Remember that a unit test function starts with test_.
The 3 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 invert(dictionary):
"""Invert Function."""
inverted_dict ={}
for key, value in dictionary.items():
if value in inverted_dict:
raise KeyError("Duplicate value encountered while inverting dictionary")
inverted_dict[value]= key
return inverted_dict
def favorite_color(colors):
"""Favorite Color Function."""
color_count ={}
for color in colors.values():
color_count[color]= color_count.get(color,0)+1
max_count = max(color_count.values())
for name, color in colors.items():
if color_count[color]== max_count:
return color
def count(lst):
"""Count Function."""
count_dict ={}
for item in lst:
if item in count_dict:
count_dict[item]+=1
else:
count_dict[item]=1
return count_dict
def alphabetizer(words):
"""Alphabetizer Function."""
alphabet_dict ={}
for word in words:
first_letter = word[0].lower()
if first_letter in alphabet_dict:
alphabet_dict[first_letter].append(word)
else:
alphabet_dict[first_letter]=[word]
return alphabet_dict
def update_attendance(attendance_log, day, student):
"""Update Attendance Function."""
if day in attendance_log:
attendance_log[day].append(student)
else:
attendance_log[day]=[student]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions

Question

40 Job pricing and pay structures.

Answered: 1 week ago