Question: Hello, I need help updating my current Python program to reflect these requirements using Python: 1 . All of the tests should run and no

Hello, I need help updating my current Python program to reflect these requirements using Python:
1. All of the tests should run and no output generated.
2. Tests will cover all of the functionality of the function and a range of the types. For instance, if you have a conditional statement, you should have a test that takes the true branch and another that takes the false branch.
3. Must have at least 5 different tests per function.
def minmax(list):
if not list:
return None, None
smallest, largest = list[0], list[0]
for num in list:
if num < smallest:
smallest = num
if num > largest:
largest = num
return smallest, largest
def test_minmax():
if minmax([1,2,3])!=(1,3):
print("Error with minmax([1,2,3])")
if minmax([-2,0,20,7])!=(-2,20):
print("Error with minmax([-2,0,20,7])")
if minmax([])!=(None, None):
print("Error with minmax([])")
else:
print("minmax Tests Passed.")
test_minmax()
def all_pairs(a, b):
result =[]
for each in a:
for other in b:
if each != other and (other, each) not in result:
result.append((each, other))
return result
def test_all_pairs():
x =[1,4,6,8]
y =[5,2,6]
expected_result =[(1,5),(1,2),(1,6),(4,5),(4,2),(4,6),(6,5),(6,2),(8,5),(8,2),(8,6)]
if all_pairs(x, y)!= expected_result:
print("Error with all_pairs([1,4,6,8],[5,2,6])")
else:
print("all_pairs Test Passed.")
test_all_pairs()
def list_to_dict(list):
return {i +1: list[i] for i in range(len(list))}
def test_list_to_dict():
list =[2,6,6,1,7,9]
expected_result ={1: 2,2: 6,3: 6,4: 1,5: 7,6: 9}
if list_to_dict(list)!= expected_result:
print("Error with list_to_dict([2,6,6,1,7,9])")
else:
print("list_to_dict Test Passed.")
test_list_to_dict()
def invert_dict(last):
inverted ={}
for key, value in last.items():
if value in inverted:
print(f"Duplicate value {value} found for key {key}. Retaining only the first occurrence.")
else:
inverted[value]= key
return inverted
def test_invert_dict():
dict ={1: 'a',2: 'b',3: 'a'}
expected_result ={'a': 3,'b': 2}
if invert_dict(dict)!= expected_result:
print("Error with invert_dict({1: 'a',2: 'b',3: 'a'})")
else:
print("invert_dict Test Passed.")
test_invert_dict()
def adds_to_target(target, Y):
seen = set()
for num in Y:
if target - num in seen:
return True
seen.add(num)
return False
def test_adds_to_target():
if adds_to_target(13,[1,6,7,3,7,10,3]):
print("Error with adds_to_target(13,[1,6,7,3,7,10,3])")
if not adds_to_target(14,[1,6,7,3,7,10,3]):
print("Error with adds_to_target(14,[1,6,7,3,7,10,3])")
else:
print("adds_to_target Test Passed.")
test_adds_to_target()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!