Skip to content

Commit db3a2da

Browse files
add one more test to check direction of shiftNodeDown
1 parent b52c7b7 commit db3a2da

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/max-heap.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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');

0 commit comments

Comments
 (0)