Add an array-based bounded queue #8
Labels
effort: medium
These issues require some work
priority: low
type: enhancement
Improve an existing feature
A bounded queue has a fixed capacity (maximum number of members). When the capacity is reached, the queue is full and no further items can be enqueued. A bounded queue can be implemented with a .
In file
queue.py
:StaticArrayQueue
as a copy ofLinkedListQueue
.__all__
list.__init__
, add an integer parametercapacity
. RaiseValueError
ifcapacity
is negative or smaller than the length of parametersequence
. Update the class's doctest to use this parameter.capacity
that returns the fixed length of the array. Use this method in the doctest.enqueue
to raiseValueError
when the stack is full. Update the docstring accordingly.In file
tests/test_queue.py
:StaticArrayQueue
to the import statement (line 7), the type definition (line 11) and theQueue
fixture (line 27)test_enqueue
andtest_dequeue
, add a functiontest_enqueue_full(sequence: Sequence)
that tests that enqueuing doesn't change the queue's capacity and thatValueError
is raised when enqueuing on a full queue. (See thecheck_is_empty
function for how to do that.)The text was updated successfully, but these errors were encountered: