@@ -5,33 +5,34 @@ describe('MaxHeap', () => {
55 expect ( typeof MaxHeap . prototype . constructor ) . toEqual ( 'function' ) ;
66 } ) ;
77
8+ const mh = new MaxHeap ( ) ;
9+
10+ beforeEach ( ( ) => {
11+ mh . destroy ( ) ;
12+ } ) ;
13+
814 it ( 'Should create an instance of MaxHeap' , ( ) => {
9- const mh = new MaxHeap ( ) ;
1015 expect ( mh instanceof MaxHeap ) . toEqual ( true ) ;
1116 } ) ;
1217
1318 it ( 'Should add an element to the MaxHeap' , ( ) => {
14- const mh = new MaxHeap ( ) ;
1519 mh . add ( 10 ) ;
1620 expect ( mh . getMax ( ) ) . toEqual ( 10 ) ;
1721 } ) ;
1822
1923 it ( 'Should keep the largest element at the root' , ( ) => {
20- const mh = new MaxHeap ( ) ;
2124 [ 12 , 5 , 34 ] . forEach ( el => mh . add ( el ) ) ;
2225 expect ( mh . getMax ( ) ) . toEqual ( 34 ) ;
2326 } ) ;
2427
2528 it ( 'Should retain Heap properties after removal of an element' , ( ) => {
26- const mh = new MaxHeap ( ) ;
2729 [ 12 , 45 , 1 , 34 ] . forEach ( el => mh . add ( el ) ) ;
2830 expect ( mh . getMax ( ) ) . toEqual ( 45 ) ;
2931 mh . remove ( ) ;
3032 expect ( mh . getMax ( ) ) . toEqual ( 34 ) ;
3133 } ) ;
3234
3335 it ( 'Should return `null` when heap is empty' , ( ) => {
34- const mh = new MaxHeap ( ) ;
3536 [ 1 , 34 ] . forEach ( el => mh . add ( el ) ) ;
3637 expect ( mh . getMax ( ) ) . toEqual ( 34 ) ;
3738 mh . remove ( ) ;
@@ -40,7 +41,6 @@ describe('MaxHeap', () => {
4041 } ) ;
4142
4243 it ( 'Should return the elelment value on `remove()`' , ( ) => {
43- const mh = new MaxHeap ( ) ;
4444 [ 1 , 34 ] . forEach ( el => mh . add ( el ) ) ;
4545 expect ( mh . getMax ( ) ) . toEqual ( 34 ) ;
4646 expect ( mh . remove ( ) ) . toEqual ( 34 ) ;
0 commit comments