File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -410,6 +410,34 @@ describe('MaxHeap', () => {
410410 expect ( h . parentNodes [ 2 ] ) . to . equal ( correctParentNodesOrderAfterShiftUp [ 2 ] ) ;
411411 } ) ;
412412
413+ it ( 'shifts node down in right direction' , ( ) => {
414+ h = new MaxHeap ( ) ;
415+
416+ let newRoot = new Node ( 20 , 20 ) ;
417+ let newDeepest = new Node ( 1 , 1 ) ;
418+
419+ h . root = newDeepest ;
420+ h . root . appendChild ( new Node ( 10 , 10 ) ) ;
421+ h . root . appendChild ( newRoot ) ;
422+ h . root . left . appendChild ( new Node ( 5 , 5 ) ) ;
423+ h . root . left . appendChild ( new Node ( 8 , 8 ) ) ;
424+ h . root . right . appendChild ( new Node ( 11 , 11 ) ) ;
425+ h . root . right . appendChild ( new Node ( 6 , 6 ) ) ;
426+
427+ /**
428+ 1 20
429+ / \ / \
430+ 10 20 - shiftDown -> 10 11
431+ / \ / \ / \ / \
432+ 5 8 11 6 5 8 0 6
433+ **/
434+
435+ h . shiftNodeDown ( h . root ) ;
436+
437+ expect ( h . root ) . to . equal ( newRoot ) ;
438+ expect ( h . root . right . left ) . to . equal ( newDeepest ) ;
439+ } ) ;
440+
413441 it ( 'calls Node.swapWithParent' , ( ) => {
414442 const firstNodeToSwapWith = h . root . left ;
415443 sinon . spy ( firstNodeToSwapWith , 'swapWithParent' ) ;
You can’t perform that action at this time.
0 commit comments