11package com .thealgorithms .datastructures .queues ;
22
3- import static org .junit .jupiter .api .Assertions .*;
3+ import static org .junit .jupiter .api .Assertions .assertEquals ;
4+ import static org .junit .jupiter .api .Assertions .assertFalse ;
5+ import static org .junit .jupiter .api .Assertions .assertNull ;
46
57import java .util .NoSuchElementException ;
68import org .junit .jupiter .api .Test ;
@@ -48,7 +50,7 @@ void testPollLast() {
4850 @ Test
4951 void testIsEmpty () {
5052 Deque <Integer > deque = new Deque <>();
51- assertTrue (deque .isEmpty ());
53+ org . junit . jupiter . api . Assertions . assertTrue (deque .isEmpty ());
5254 deque .addFirst (10 );
5355 assertFalse (deque .isEmpty ());
5456 }
@@ -68,13 +70,13 @@ void testPeekLastEmpty() {
6870 @ Test
6971 void testPollFirstEmpty () {
7072 Deque <Integer > deque = new Deque <>();
71- assertThrows (NoSuchElementException .class , deque ::pollFirst );
73+ org . junit . jupiter . api . Assertions . assertThrows (NoSuchElementException .class , deque ::pollFirst );
7274 }
7375
7476 @ Test
7577 void testPollLastEmpty () {
7678 Deque <Integer > deque = new Deque <>();
77- assertThrows (NoSuchElementException .class , deque ::pollLast );
79+ org . junit . jupiter . api . Assertions . assertThrows (NoSuchElementException .class , deque ::pollLast );
7880 }
7981
8082 @ Test
@@ -95,6 +97,28 @@ void testAlternatingAddRemove() {
9597 assertEquals (0 , deque .pollFirst ());
9698 assertEquals (2 , deque .pollLast ());
9799 assertEquals (1 , deque .pollFirst ());
98- assertTrue (deque .isEmpty ());
100+ org .junit .jupiter .api .Assertions .assertTrue (deque .isEmpty ());
101+ }
102+
103+ @ Test
104+ void testSizeAfterOperations () {
105+ Deque <Integer > deque = new Deque <>();
106+ assertEquals (0 , deque .size ());
107+ deque .addFirst (1 );
108+ deque .addLast (2 );
109+ deque .addFirst (3 );
110+ assertEquals (3 , deque .size ());
111+ deque .pollFirst ();
112+ deque .pollLast ();
113+ assertEquals (1 , deque .size ());
114+ }
115+
116+ @ Test
117+ void testNullValues () {
118+ Deque <String > deque = new Deque <>();
119+ deque .addFirst (null );
120+ assertNull (deque .peekFirst ());
121+ assertNull (deque .pollFirst ());
122+ org .junit .jupiter .api .Assertions .assertTrue (deque .isEmpty ());
99123 }
100124}
0 commit comments