Question
C an you help me to fix the code for LWPriorityQueue() and import Callable thank you codes bellow code 1; q = LWPriorityQueue() test_in =
Can you help me to fix the code for LWPriorityQueue() and import Callable
thank you codes bellow
code 1;
q = LWPriorityQueue()
test_in = [] #normal order, duplicate priorities/people test_in.append([{'complete_time': 45, 'customer': 'AJ', 'priority': 4, 'task': 'belt'}, {'complete_time': 45, 'customer': 'Stu', 'priority': 9, 'task': 'belt'}, {'complete_time': 60, 'customer': 'Alex', 'priority': 12, 'task': 'wallet'}, {'complete_time': 45, 'customer': 'Alex', 'priority': 12, 'task': 'belt'}]) #reverse order, duplicate priorities/people test_in.append([ {'complete_time': 45, 'customer': 'Alex', 'priority': 12, 'task': 'belt'}, {'complete_time': 60, 'customer': 'Alex', 'priority': 12, 'task': 'wallet'}, {'complete_time': 45, 'customer': 'Stu', 'priority': 9, 'task': 'belt'}, {'complete_time': 45, 'customer': 'AJ', 'priority': 4, 'task': 'belt'} ]) #empty queue test_in.append([]) #single item test_in.append([{'complete_time': 45, 'customer': 'Stu', 'priority': 9, 'task': 'belt'}]) #two items, same priority test_in.append([{'complete_time': 45, 'customer': 'Stu', 'priority': 9, 'task': 'belt'}, {'complete_time': 45, 'customer': 'Steve', 'priority': 9, 'task': 'wallet'}])
test_out = [] test_out.append([{'complete_time': 45, 'customer': 'AJ', 'priority': 0, 'task': 'belt'}, {'complete_time': 45, 'customer': 'Stu', 'priority': 1, 'task': 'belt'}, {'complete_time': 60, 'customer': 'Alex', 'priority': 2, 'task': 'wallet'}, {'complete_time': 45, 'customer': 'Alex', 'priority': 2, 'task': 'belt'}]) test_out.append([{'complete_time': 45, 'customer': 'Alex', 'priority': 2, 'task': 'belt'}, {'complete_time': 60, 'customer': 'Alex', 'priority': 2, 'task': 'wallet'}, {'complete_time': 45, 'customer': 'Stu', 'priority': 1, 'task': 'belt'}, {'complete_time': 45, 'customer': 'AJ', 'priority': 0, 'task': 'belt'}]) test_out.append([]) test_out.append([{'complete_time': 45, 'customer': 'Stu', 'priority': 0, 'task': 'belt'}]) test_out.append([{'complete_time': 45, 'customer': 'Stu', 'priority': 0, 'task': 'belt'}, {'complete_time': 45, 'customer': 'Steve', 'priority': 0, 'task': 'wallet'}]) for i in range(len(test_in)): print('Test',i+1,end=": ") q.items = test_in[i] q.compact() if (q.items == test_out[i]): print("Passed") else: print("Failed")
CODE 2;
from typing import Callable
def test(function: Callable, test_table: list) -> None: """Test the function with the test_table. Report failed tests.
Preconditions: each element of test_table is a list or tuple with - a string (the test case name) - one or more values (the inputs to the function) - the expected output value """ for test_case in test_table: name = test_case[0] inputs = test_case[1:-1] expected = test_case[-1] actual = function(*inputs) if actual != expected: print(name, 'FAILED:', actual, 'instead of', expected) print('Tests finished.')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started