Add doctest for circular queue overflow condition (#13590)
* Add doctest for circular queue overflow condition Added a doctest to test the QUEUE IS FULL exception when attempting to enqueue an element into a full circular queue. This improves test coverage for line 67 in data_structures/queues/circular_queue.py. Fixes #9943 * Update circular_queue.py * Update circular_queue.py * Update circular_queue.py * Update circular_queue.py --------- Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
This commit is contained in:
@@ -17,7 +17,7 @@ class CircularQueue:
|
||||
>>> len(cq)
|
||||
0
|
||||
>>> cq.enqueue("A") # doctest: +ELLIPSIS
|
||||
<data_structures.queues.circular_queue.CircularQueue object at ...
|
||||
<data_structures.queues.circular_queue.CircularQueue object at ...>
|
||||
>>> cq.array
|
||||
['A', None, None, None, None]
|
||||
>>> len(cq)
|
||||
@@ -51,17 +51,24 @@ class CircularQueue:
|
||||
"""
|
||||
This function inserts an element at the end of the queue using self.rear value
|
||||
as an index.
|
||||
|
||||
>>> cq = CircularQueue(5)
|
||||
>>> cq.enqueue("A") # doctest: +ELLIPSIS
|
||||
<data_structures.queues.circular_queue.CircularQueue object at ...
|
||||
<data_structures.queues.circular_queue.CircularQueue object at ...>
|
||||
>>> (cq.size, cq.first())
|
||||
(1, 'A')
|
||||
>>> cq.enqueue("B") # doctest: +ELLIPSIS
|
||||
<data_structures.queues.circular_queue.CircularQueue object at ...
|
||||
<data_structures.queues.circular_queue.CircularQueue object at ...>
|
||||
>>> cq.array
|
||||
['A', 'B', None, None, None]
|
||||
>>> (cq.size, cq.first())
|
||||
(2, 'A')
|
||||
>>> cq.enqueue("C").enqueue("D").enqueue("E") # doctest: +ELLIPSIS
|
||||
<data_structures.queues.circular_queue.CircularQueue object at ...>
|
||||
>>> cq.enqueue("F")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
Exception: QUEUE IS FULL
|
||||
"""
|
||||
if self.size >= self.n:
|
||||
raise Exception("QUEUE IS FULL")
|
||||
@@ -75,6 +82,7 @@ class CircularQueue:
|
||||
"""
|
||||
This function removes an element from the queue using on self.front value as an
|
||||
index and returns it
|
||||
|
||||
>>> cq = CircularQueue(5)
|
||||
>>> cq.dequeue()
|
||||
Traceback (most recent call last):
|
||||
|
||||
Reference in New Issue
Block a user