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:
Tejasrahane
2025-10-20 02:21:11 +05:30
committed by GitHub
parent c79034ca21
commit 3b08413ab3

View File

@@ -17,7 +17,7 @@ class CircularQueue:
>>> len(cq) >>> len(cq)
0 0
>>> cq.enqueue("A") # doctest: +ELLIPSIS >>> cq.enqueue("A") # doctest: +ELLIPSIS
<data_structures.queues.circular_queue.CircularQueue object at ... <data_structures.queues.circular_queue.CircularQueue object at ...>
>>> cq.array >>> cq.array
['A', None, None, None, None] ['A', None, None, None, None]
>>> len(cq) >>> len(cq)
@@ -51,17 +51,24 @@ class CircularQueue:
""" """
This function inserts an element at the end of the queue using self.rear value This function inserts an element at the end of the queue using self.rear value
as an index. as an index.
>>> cq = CircularQueue(5) >>> cq = CircularQueue(5)
>>> cq.enqueue("A") # doctest: +ELLIPSIS >>> 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()) >>> (cq.size, cq.first())
(1, 'A') (1, 'A')
>>> cq.enqueue("B") # doctest: +ELLIPSIS >>> cq.enqueue("B") # doctest: +ELLIPSIS
<data_structures.queues.circular_queue.CircularQueue object at ... <data_structures.queues.circular_queue.CircularQueue object at ...>
>>> cq.array >>> cq.array
['A', 'B', None, None, None] ['A', 'B', None, None, None]
>>> (cq.size, cq.first()) >>> (cq.size, cq.first())
(2, 'A') (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: if self.size >= self.n:
raise Exception("QUEUE IS FULL") 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 This function removes an element from the queue using on self.front value as an
index and returns it index and returns it
>>> cq = CircularQueue(5) >>> cq = CircularQueue(5)
>>> cq.dequeue() >>> cq.dequeue()
Traceback (most recent call last): Traceback (most recent call last):