@@ -128,4 +128,82 @@ public void testIsEmptyAfterDeletion() {
128128 list .delete (10 );
129129 assertTrue (list .isEmpty ());
130130 }
131+
132+ @ Test
133+ public void testInsertNegativeNumbers () {
134+ list .insert (-10 );
135+ list .insert (-5 );
136+ list .insert (-20 );
137+ assertEquals ("[-20, -10, -5]" , list .toString ());
138+ }
139+
140+ @ Test
141+ public void testInsertMixedPositiveAndNegativeNumbers () {
142+ list .insert (0 );
143+ list .insert (-1 );
144+ list .insert (1 );
145+ assertEquals ("[-1, 0, 1]" , list .toString ());
146+ }
147+
148+ @ Test
149+ public void testMultipleDeletesUntilEmpty () {
150+ list .insert (2 );
151+ list .insert (4 );
152+ list .insert (6 );
153+ assertTrue (list .delete (4 ));
154+ assertTrue (list .delete (2 ));
155+ assertTrue (list .delete (6 ));
156+ assertTrue (list .isEmpty ());
157+ assertEquals ("[]" , list .toString ());
158+ }
159+
160+ @ Test
161+ public void testDeleteDuplicateValuesOnlyDeletesOneInstance () {
162+ list .insert (5 );
163+ list .insert (5 );
164+ list .insert (5 );
165+ assertTrue (list .delete (5 ));
166+ assertEquals ("[5, 5]" , list .toString ());
167+ assertTrue (list .delete (5 ));
168+ assertEquals ("[5]" , list .toString ());
169+ assertTrue (list .delete (5 ));
170+ assertEquals ("[]" , list .toString ());
171+ }
172+
173+ @ Test
174+ public void testSearchOnListWithDuplicates () {
175+ list .insert (7 );
176+ list .insert (7 );
177+ list .insert (7 );
178+ assertTrue (list .search (7 ));
179+ assertFalse (list .search (10 ));
180+ }
181+
182+ @ Test
183+ public void testToStringOnEmptyList () {
184+ assertEquals ("[]" , list .toString ());
185+ }
186+
187+
188+ @ Test
189+ public void testDeleteAllDuplicates () {
190+ list .insert (4 );
191+ list .insert (4 );
192+ list .insert (4 );
193+ assertTrue (list .delete (4 ));
194+ assertTrue (list .delete (4 ));
195+ assertTrue (list .delete (4 ));
196+ assertFalse (list .delete (4 )); // nothing left to delete
197+ assertEquals ("[]" , list .toString ());
198+ }
199+
200+ @ Test
201+ public void testInsertAfterDeletion () {
202+ list .insert (1 );
203+ list .insert (3 );
204+ list .insert (5 );
205+ assertTrue (list .delete (3 ));
206+ list .insert (2 );
207+ assertEquals ("[1, 2, 5]" , list .toString ());
208+ }
131209}
0 commit comments