@@ -124,4 +124,204 @@ void testQueueCapacityException() {
124124 Assertions .assertThrows (IllegalArgumentException .class , () -> new Queue <>(0 ));
125125 Assertions .assertThrows (IllegalArgumentException .class , () -> new Queue <>(-5 ));
126126 }
127+
128+ @ Test
129+ void testCircularBehavior () {
130+ // Test that queue behaves correctly after multiple insert/remove cycles
131+ queue .insert (1 );
132+ queue .insert (2 );
133+ queue .insert (3 );
134+
135+ // Remove all elements
136+ queue .remove (); // removes 1
137+ queue .remove (); // removes 2
138+ queue .remove (); // removes 3
139+
140+ // Add elements again to test circular behavior
141+ queue .insert (4 );
142+ queue .insert (5 );
143+ queue .insert (6 );
144+
145+ Assertions .assertEquals (4 , queue .peekFront ());
146+ Assertions .assertEquals (6 , queue .peekRear ());
147+ Assertions .assertEquals (3 , queue .getSize ());
148+ Assertions .assertTrue (queue .isFull ());
149+ }
150+
151+ @ Test
152+ void testMixedInsertRemoveOperations () {
153+ // Test interleaved insert and remove operations
154+ queue .insert (1 );
155+ queue .insert (2 );
156+
157+ Assertions .assertEquals (1 , queue .remove ());
158+ queue .insert (3 );
159+ queue .insert (4 );
160+
161+ Assertions .assertEquals (2 , queue .remove ());
162+ Assertions .assertEquals (3 , queue .remove ());
163+
164+ queue .insert (5 );
165+ queue .insert (6 );
166+
167+ Assertions .assertEquals (4 , queue .peekFront ());
168+ Assertions .assertEquals (6 , queue .peekRear ());
169+ Assertions .assertEquals (3 , queue .getSize ());
170+ }
171+
172+ @ Test
173+ void testSingleElementOperations () {
174+ // Test operations with single element
175+ queue .insert (42 );
176+
177+ Assertions .assertEquals (42 , queue .peekFront ());
178+ Assertions .assertEquals (42 , queue .peekRear ());
179+ Assertions .assertEquals (1 , queue .getSize ());
180+ Assertions .assertFalse (queue .isEmpty ());
181+ Assertions .assertFalse (queue .isFull ());
182+
183+ Assertions .assertEquals (42 , queue .remove ());
184+ Assertions .assertTrue (queue .isEmpty ());
185+ Assertions .assertEquals (0 , queue .getSize ());
186+ }
187+
188+ @ Test
189+ void testNullValueHandling () {
190+ // Test queue with null values (if supported)
191+ Queue <String > stringQueue = new Queue <>(3 );
192+
193+ Assertions .assertTrue (stringQueue .insert (null ));
194+ Assertions .assertTrue (stringQueue .insert ("test" ));
195+ Assertions .assertTrue (stringQueue .insert (null ));
196+
197+ Assertions .assertNull (stringQueue .peekFront ());
198+ Assertions .assertNull (stringQueue .peekRear ());
199+ Assertions .assertEquals (3 , stringQueue .getSize ());
200+
201+ Assertions .assertNull (stringQueue .remove ());
202+ Assertions .assertEquals ("test" , stringQueue .peekFront ());
203+ }
204+
205+ @ Test
206+ void testStringDataType () {
207+ // Test queue with String data type
208+ Queue <String > stringQueue = new Queue <>(2 );
209+ stringQueue .insert ("first" );
210+ stringQueue .insert ("second" );
211+
212+ Assertions .assertEquals ("first" , stringQueue .peekFront ());
213+ Assertions .assertEquals ("second" , stringQueue .peekRear ());
214+ }
215+
216+ @ Test
217+ void testLargerCapacityQueue () {
218+ // Test queue with larger capacity
219+ Queue <Integer > largeQueue = new Queue <>(10 );
220+
221+ // Fill the queue
222+ for (int i = 1 ; i <= 10 ; i ++) {
223+ Assertions .assertTrue (largeQueue .insert (i ));
224+ }
225+
226+ Assertions .assertTrue (largeQueue .isFull ());
227+ Assertions .assertFalse (largeQueue .insert (11 ));
228+
229+ // Remove half the elements
230+ for (int i = 1 ; i <= 5 ; i ++) {
231+ Assertions .assertEquals (i , largeQueue .remove ());
232+ }
233+
234+ Assertions .assertEquals (6 , largeQueue .peekFront ());
235+ Assertions .assertEquals (10 , largeQueue .peekRear ());
236+ Assertions .assertEquals (5 , largeQueue .getSize ());
237+ }
238+
239+ @ Test
240+ void testQueueCapacityOne () {
241+ // Test queue with capacity of 1
242+ Queue <Integer > singleQueue = new Queue <>(1 );
243+
244+ Assertions .assertTrue (singleQueue .isEmpty ());
245+ Assertions .assertFalse (singleQueue .isFull ());
246+
247+ Assertions .assertTrue (singleQueue .insert (100 ));
248+ Assertions .assertTrue (singleQueue .isFull ());
249+ Assertions .assertFalse (singleQueue .isEmpty ());
250+ Assertions .assertFalse (singleQueue .insert (200 ));
251+
252+ Assertions .assertEquals (100 , singleQueue .peekFront ());
253+ Assertions .assertEquals (100 , singleQueue .peekRear ());
254+
255+ Assertions .assertEquals (100 , singleQueue .remove ());
256+ Assertions .assertTrue (singleQueue .isEmpty ());
257+ }
258+
259+ @ Test
260+ void testQueueWraparoundIndexing () {
261+ // Test that internal array indexing wraps around correctly
262+ queue .insert (1 );
263+ queue .insert (2 );
264+ queue .insert (3 ); // Queue full
265+
266+ // Remove one element
267+ queue .remove (); // removes 1
268+
269+ // Add another element (should wrap around)
270+ queue .insert (4 );
271+
272+ Assertions .assertEquals ("[2, 3, 4]" , queue .toString ());
273+ Assertions .assertEquals (2 , queue .peekFront ());
274+ Assertions .assertEquals (4 , queue .peekRear ());
275+
276+ // Continue the pattern
277+ queue .remove (); // removes 2
278+ queue .insert (5 );
279+
280+ Assertions .assertEquals (3 , queue .peekFront ());
281+ Assertions .assertEquals (5 , queue .peekRear ());
282+ }
283+
284+ @ Test
285+ void testQueueStateAfterMultipleCycles () {
286+ // Test queue state after multiple complete fill/empty cycles
287+ for (int cycle = 0 ; cycle < 3 ; cycle ++) {
288+ // Fill the queue
289+ for (int i = 1 ; i <= 3 ; i ++) {
290+ queue .insert (i + cycle * 10 );
291+ }
292+
293+ // Verify state
294+ Assertions .assertTrue (queue .isFull ());
295+ Assertions .assertEquals (3 , queue .getSize ());
296+
297+ // Empty the queue
298+ for (int i = 1 ; i <= 3 ; i ++) {
299+ queue .remove ();
300+ }
301+
302+ // Verify empty state
303+ Assertions .assertTrue (queue .isEmpty ());
304+ Assertions .assertEquals (0 , queue .getSize ());
305+ }
306+ }
307+
308+ @ Test
309+ void testQueueConsistencyAfterOperations () {
310+ // Test that queue maintains consistency after various operations
311+ queue .insert (10 );
312+ queue .insert (20 );
313+
314+ int firstRemoved = queue .remove ();
315+ queue .insert (30 );
316+ queue .insert (40 );
317+
318+ int secondRemoved = queue .remove ();
319+ queue .insert (50 );
320+
321+ // Verify the order is maintained
322+ Assertions .assertEquals (10 , firstRemoved );
323+ Assertions .assertEquals (20 , secondRemoved );
324+ Assertions .assertEquals (30 , queue .peekFront ());
325+ Assertions .assertEquals (50 , queue .peekRear ());
326+ }
127327}
0 commit comments