33import static org .junit .jupiter .api .Assertions .assertEquals ;
44import static org .junit .jupiter .api .Assertions .assertFalse ;
55import static org .junit .jupiter .api .Assertions .assertNull ;
6+ import static org .junit .jupiter .api .Assertions .assertThrows ;
7+ import static org .junit .jupiter .api .Assertions .assertTrue ;
68
79import java .util .NoSuchElementException ;
810import org .junit .jupiter .api .Test ;
@@ -50,7 +52,7 @@ void testPollLast() {
5052 @ Test
5153 void testIsEmpty () {
5254 Deque <Integer > deque = new Deque <>();
53- org . junit . jupiter . api . Assertions . assertTrue (deque .isEmpty ());
55+ assertTrue (deque .isEmpty ());
5456 deque .addFirst (10 );
5557 assertFalse (deque .isEmpty ());
5658 }
@@ -70,13 +72,13 @@ void testPeekLastEmpty() {
7072 @ Test
7173 void testPollFirstEmpty () {
7274 Deque <Integer > deque = new Deque <>();
73- org . junit . jupiter . api . Assertions . assertThrows (NoSuchElementException .class , deque ::pollFirst );
75+ assertThrows (NoSuchElementException .class , deque ::pollFirst );
7476 }
7577
7678 @ Test
7779 void testPollLastEmpty () {
7880 Deque <Integer > deque = new Deque <>();
79- org . junit . jupiter . api . Assertions . assertThrows (NoSuchElementException .class , deque ::pollLast );
81+ assertThrows (NoSuchElementException .class , deque ::pollLast );
8082 }
8183
8284 @ Test
@@ -87,4 +89,22 @@ void testToString() {
8789 deque .addFirst (5 );
8890 assertEquals ("Head -> 5 <-> 10 <-> 20 <- Tail" , deque .toString ());
8991 }
92+
93+ @ Test
94+ void testAlternatingAddRemove () {
95+ Deque <Integer > deque = new Deque <>();
96+ deque .addFirst (1 );
97+ deque .addLast (2 );
98+ deque .addFirst (0 );
99+ assertEquals (0 , deque .pollFirst ());
100+ assertEquals (2 , deque .pollLast ());
101+ assertEquals (1 , deque .pollFirst ());
102+ assertTrue (deque .isEmpty ());
103+ }
104+
105+ @ Test
106+ void testAddNull () {
107+ Deque <Integer > deque = new Deque <>();
108+ assertThrows (NullPointerException .class , () -> deque .addFirst (null ));
109+ }
90110}
0 commit comments