data-structure-typed/test/integration/heap.test.js
Revone fc0d157295 refactor: Test coverage increased to 95.63%.
Upgraded all dependencies.
Added a toVisual method while retaining the print method.
Replaced all short-circuit evaluations with logical expressions.
2024-10-30 15:30:28 +13:00

22 lines
671 B
JavaScript

const { MinHeap } = require('heap-typed');
describe('JS Heap Operation Test', () => {
it('should numeric heap work well', function () {
const minNumHeap = new MinHeap();
minNumHeap.add(1);
minNumHeap.add(6);
minNumHeap.add(2);
minNumHeap.add(0);
minNumHeap.add(5);
minNumHeap.add(9);
expect(minNumHeap.poll()).toBe(0);
expect(minNumHeap.poll()).toBe(1);
expect(minNumHeap.peek()).toBe(2);
expect(minNumHeap.toArray().length).toBe(4);
expect(minNumHeap.toArray()[0]).toBe(2);
expect(minNumHeap.toArray()[1]).toBe(5);
expect(minNumHeap.toArray()[2]).toBe(9);
expect(minNumHeap.toArray()[3]).toBe(6);
});
});