Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer in Python. Fill in where it says YOUR CODE HERE. Make sure it passes the tests provided _getitem [41] def counting_queue_getitem(self, n): # YOUR

Answer in Python. Fill in where it says YOUR CODE HERE. Make sure it passes the tests providedimage text in transcribedimage text in transcribedimage text in transcribed

_getitem [41] def counting_queue_getitem(self, n): # YOUR CODE HERE CountingQueue. getitem = counting_queue_getitem [42] # 5 points: simple tests. q = CountingQueue () q.add("cat", count=2) q.add("dog", count=3) q.add("bird", count=4) els = [q[i] for i in range(9)] assert els == ['cat'] * 2 + ['dog'] * 3+ ['bird'] * 4 # Let's do it again. els = [q[i] for i in range(9)] assert els l'cat'* 2tal dog'lub'bird' 1*4 # 5 points: you raise IndexError when accessing elements out of bounds. q = CountingQueue() q.add("cat", count=2) q.add("dog", count=3) # Raise IndexError when it's too high... try: q[5] assert False."Failed to raise IndexError" except IndexError: pass assert q[4] == "dog" try: q[5] assert False, "Failed to raise IndexError" except IndexError: pass # And also when it's too low. try: q[-10] assert False, "Failed to raise IndexError" except IndexError: pass # or too large : try: q[10] assert False, "Failed to raise IndexError" except IndexError: pass # And raise TypeError if you try to index with a non-integer. try: q["hello"] assert False, "Failed to raise TypeError" except TypeError: pass [ 43 ] # 5 points. Behaves the same as Queue. elements = range(3) for k in range(100): qo = Queue () q1 = CountingQueue ( ) for m in range (40): el = random.choice (elements) qo.add(el) ql.add(el) for i in range(m): assert qolih qi[i]

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

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions

Question

Explain how to build high-performance service delivery teams.

Answered: 1 week ago

Question

Understand what a service-oriented culture is.

Answered: 1 week ago