Question: Use the given outlines below for circular_queue.py and circular_queue_tests.py #circular_queue.py from __future__ import annotations from typing import Any class CircularQueue: def __init__(self) -> None: self.capacity

 Use the given outlines below for circular_queue.py and circular_queue_tests.py #circular_queue.py from

Use the given outlines below for circular_queue.py and circular_queue_tests.py

#circular_queue.py

from __future__ import annotations

from typing import Any

class CircularQueue: def __init__(self) -> None: self.capacity = 4 self.array: list[Any] = [None] * self.capacity self.start = 0 self.size = 0

def empty_queue() -> CircularQueue: ...

def enqueue(queue: CircularQueue, value: Any) -> None: ...

def dequeue(queue: CircularQueue) -> Any: ...

def peek(queue: CircularQueue) -> Any: ...

def is_empty(queue: CircularQueue) -> bool: ...

def size(queue: CircularQueue) -> int: ...

#circular_queue_tests.py

from __future__ import annotations

import unittest

from circular_queue import dequeue, empty_queue, enqueue, is_empty, peek, size

class Tests(unittest.TestCase): def test_enqueue_one_value(self) -> None: my_queue = empty_queue() enqueue(my_queue, 10)

self.assertEqual(my_queue.capacity, 4) self.assertEqual(my_queue.array[0], 10) self.assertEqual(my_queue.start, 0) self.assertEqual(my_queue.size, 1)

# TODO: add more tests!

if __name__ == "__main__": unittest.main()

Details of each operation are given below; you will implement these operations for a link-based implementation and for a circular array implementation. You must verify, via test cases, that your implementations behave as expected (i.e., that they "work"). - empty_queue This function takes no arguments and returns an empty queue. - enqueue This function takes a queue and a value as arguments and adds the value to the "end" of the queue. Because both of our implementations will mutate the data structure, this function need not (and should not) return anything. - dequeue This function takes a queue as an argument and removes (and returns) the value at the "front" of the queue. If the queue is empty, then this operation should raise an IndexError. Again, because we will be mutating the data structure itself with the removal, we will only return the value being dequeued. - peek This function takes a queue as an argument and returns (without removing) the value at the "front" of the queue. If the queue is empty, then this operation should raise an IndexError. - is_empty This function takes a queue as an argument and returns whether or not the queue is empty. - size This function takes a queue as an argument and returns the number of items in the queue. For both implementations, these should all be O(1) (i.e., constant time) operations. In a file named circular_queue.py, define the CircularQueue class for a circular array-based queue implementation and implement the aforementioned queue operations. Be sure that all of them are O(1). The circular buffer allows for tracking the head of the queue as an index into the array. Values are not shifted as the result of a dequeue operation; instead, the index for the head of the queue is simply updated. Similarly, the number of elements currently in the queue is tracked and updated as values are enqueued. If we left it at that, then the queue would waste the space at the beginning of the array after each dequeue operations. Instead, the queue will "wrap around" to the beginning of the array when we read the end. Hence the name "circular" queue. Place your test cases in a file named circular_queue_tests.py Note: similar to our lab implementing a list structure, you are prohibited from using almost all of Python's list operations in your implementation. The only list operations you may use are: - initializing with a specific size (through the * operator, e.g., [None] * 100), which will act as "allocating a new array", and - indexing (e.g., my_queue [4] ) Every other builtin Python operation dealing with lists is expressly forbidden

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 Databases Questions!