@@ -175,7 +175,7 @@ describe('Data Structures: Linked Lists', () => {
175
175
list . addAtEnd ( 'There!' ) ;
176
176
list . addAtEnd ( 'Welcome' ) ;
177
177
} ) ;
178
-
178
+
179
179
it ( 'Should return `null` for empty list regardless of index value' , ( ) => {
180
180
list . delete ( ) ;
181
181
expect ( list . getAt ( 10 ) ) . toEqual ( null ) ;
@@ -189,5 +189,32 @@ describe('Data Structures: Linked Lists', () => {
189
189
expect ( list . getAt ( 10 ) . data ) . toEqual ( 'Welcome' ) ;
190
190
} ) ;
191
191
} ) ;
192
+
193
+ describe ( 'addAt(index, value)' , ( ) => {
194
+ beforeEach ( ( ) => {
195
+ list . addAtBeginning ( 'Hello' ) ;
196
+ list . addAtEnd ( 'There!' ) ;
197
+ list . addAtEnd ( 'Welcome' ) ;
198
+ } ) ;
199
+
200
+ it ( 'Should add at the beginning of empty list' , ( ) => {
201
+ list . delete ( ) ;
202
+ list . addAt ( 10 , 'Boom' ) ;
203
+ expect ( list . getFirst ( ) . data ) . toEqual ( 'Boom' ) ;
204
+ } ) ;
205
+
206
+ it ( 'Should add at the end of the list if the index is out of bound' , ( ) => {
207
+ list . addAtEnd ( 1010 ) ;
208
+ list . addAt ( 10 , 'Boom' ) ;
209
+ expect ( list . getLast ( ) . data ) . toEqual ( 'Boom' ) ;
210
+ } ) ;
211
+
212
+ it ( 'Should add new element at the given position' , ( ) => {
213
+ list . addAt ( 2 , 'Stranger' ) ;
214
+ expect ( list . getAt ( 2 ) . data ) . toEqual ( 'Stranger' ) ;
215
+ expect ( list . getAt ( 1 ) . data ) . toEqual ( 'There!' ) ;
216
+ expect ( list . getAt ( 0 ) . data ) . toEqual ( 'Hello' ) ;
217
+ } ) ;
218
+ } ) ;
192
219
} ) ;
193
220
} ) ;
0 commit comments