Skip to content

Commit 3b08413

Browse files
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>
1 parent c79034c commit 3b08413

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

data_structures/queues/circular_queue.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __len__(self) -> int:
1717
>>> len(cq)
1818
0
1919
>>> cq.enqueue("A") # doctest: +ELLIPSIS
20-
<data_structures.queues.circular_queue.CircularQueue object at ...
20+
<data_structures.queues.circular_queue.CircularQueue object at ...>
2121
>>> cq.array
2222
['A', None, None, None, None]
2323
>>> len(cq)
@@ -51,17 +51,24 @@ def enqueue(self, data):
5151
"""
5252
This function inserts an element at the end of the queue using self.rear value
5353
as an index.
54+
5455
>>> cq = CircularQueue(5)
5556
>>> cq.enqueue("A") # doctest: +ELLIPSIS
56-
<data_structures.queues.circular_queue.CircularQueue object at ...
57+
<data_structures.queues.circular_queue.CircularQueue object at ...>
5758
>>> (cq.size, cq.first())
5859
(1, 'A')
5960
>>> cq.enqueue("B") # doctest: +ELLIPSIS
60-
<data_structures.queues.circular_queue.CircularQueue object at ...
61+
<data_structures.queues.circular_queue.CircularQueue object at ...>
6162
>>> cq.array
6263
['A', 'B', None, None, None]
6364
>>> (cq.size, cq.first())
6465
(2, 'A')
66+
>>> cq.enqueue("C").enqueue("D").enqueue("E") # doctest: +ELLIPSIS
67+
<data_structures.queues.circular_queue.CircularQueue object at ...>
68+
>>> cq.enqueue("F")
69+
Traceback (most recent call last):
70+
...
71+
Exception: QUEUE IS FULL
6572
"""
6673
if self.size >= self.n:
6774
raise Exception("QUEUE IS FULL")
@@ -75,6 +82,7 @@ def dequeue(self):
7582
"""
7683
This function removes an element from the queue using on self.front value as an
7784
index and returns it
85+
7886
>>> cq = CircularQueue(5)
7987
>>> cq.dequeue()
8088
Traceback (most recent call last):

0 commit comments

Comments
 (0)