2023-09-09 15:49:53 +00:00
|
|
|
const {MinHeap} = require('heap-typed');
|
2023-08-30 16:18:13 +00:00
|
|
|
|
|
|
|
describe('JS Heap Operation Test', () => {
|
|
|
|
it('should numeric heap work well', function () {
|
|
|
|
const minNumHeap = new MinHeap();
|
2023-08-31 12:02:31 +00:00
|
|
|
minNumHeap.add(1).add(6).add(2).add(0).add(5).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);
|
2023-08-30 16:18:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|