@@ -169,51 +169,63 @@ describe('Data Structures: Linked Lists', () => {
169
169
} ) ;
170
170
} ) ;
171
171
172
- describe ( 'getAt(index) ' , ( ) => {
172
+ describe ( 'Get/Add/Remove at specific positions ' , ( ) => {
173
173
beforeEach ( ( ) => {
174
174
list . addAtBeginning ( 'Hello' ) ;
175
175
list . addAtEnd ( 'There!' ) ;
176
176
list . addAtEnd ( 'Welcome' ) ;
177
177
} ) ;
178
178
179
- it ( 'Should return `null` for empty list regardless of index value' , ( ) => {
180
- list . delete ( ) ;
181
- expect ( list . getAt ( 10 ) ) . toEqual ( null ) ;
182
- } ) ;
183
-
184
- it ( 'Should return the node for given index' , ( ) => {
185
- expect ( list . getAt ( 1 ) . data ) . toEqual ( 'There!' ) ;
186
- } ) ;
187
-
188
- it ( 'Should return the last element for large index' , ( ) => {
189
- expect ( list . getAt ( 10 ) . data ) . toEqual ( 'Welcome' ) ;
190
- } ) ;
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' ) ;
179
+ describe ( 'getAt(index)' , ( ) => {
180
+ it ( 'Should return `null` for empty list regardless of index value' , ( ) => {
181
+ list . delete ( ) ;
182
+ expect ( list . getAt ( 10 ) ) . toEqual ( null ) ;
183
+ } ) ;
184
+
185
+ it ( 'Should return the node for given index' , ( ) => {
186
+ expect ( list . getAt ( 1 ) . data ) . toEqual ( 'There!' ) ;
187
+ } ) ;
188
+
189
+ it ( 'Should return the last element for large index' , ( ) => {
190
+ expect ( list . getAt ( 10 ) . data ) . toEqual ( 'Welcome' ) ;
191
+ } ) ;
192
+ } ) ;
193
+
194
+ describe ( 'addAt(index, value)' , ( ) => {
195
+ it ( 'Should add at the beginning of empty list' , ( ) => {
196
+ list . delete ( ) ;
197
+ list . addAt ( 10 , 'Boom' ) ;
198
+ expect ( list . getFirst ( ) . data ) . toEqual ( 'Boom' ) ;
199
+ } ) ;
200
+
201
+ it ( 'Should add at the end of the list if the index is out of bound' , ( ) => {
202
+ list . addAtEnd ( 1010 ) ;
203
+ list . addAt ( 10 , 'Boom' ) ;
204
+ expect ( list . getLast ( ) . data ) . toEqual ( 'Boom' ) ;
205
+ } ) ;
206
+
207
+ it ( 'Should add new element at the given position' , ( ) => {
208
+ list . addAt ( 2 , 'Stranger' ) ;
209
+ expect ( list . getAt ( 2 ) . data ) . toEqual ( 'Stranger' ) ;
210
+ expect ( list . getAt ( 1 ) . data ) . toEqual ( 'There!' ) ;
211
+ expect ( list . getAt ( 0 ) . data ) . toEqual ( 'Hello' ) ;
212
+ } ) ;
213
+ } ) ;
214
+
215
+ describe ( 'removeAt(index)' , ( ) => {
216
+ it ( 'Should return null for empty list' , ( ) => {
217
+ list . delete ( ) ;
218
+ expect ( list . removeAt ( 10 ) ) . toEqual ( null ) ;
219
+ } ) ;
220
+
221
+ it ( 'Should remove last element for large index value' , ( ) => {
222
+ expect ( list . removeAt ( 10 ) ) . toEqual ( 'Welcome' ) ;
223
+ } ) ;
224
+
225
+ it ( 'Should remove the element at given index value' , ( ) => {
226
+ expect ( list . removeAt ( 3 ) ) . toEqual ( 'Welcome' ) ;
227
+ expect ( list . removeAt ( 2 ) ) . toEqual ( 'There!' ) ;
228
+ } ) ;
217
229
} ) ;
218
230
} ) ;
219
231
} ) ;
0 commit comments