diff --git a/scripts/dsa.js b/scripts/dsa.js index c2b32a1..bd3ef94 100644 --- a/scripts/dsa.js +++ b/scripts/dsa.js @@ -38,7 +38,7 @@ module.exports = { MinHeap: { type: "class", methods: [{ - name: "push", + name: "insert", args: "value: number", return: "void", }, { diff --git a/src/__tests__/MinHeap.ts b/src/__tests__/MinHeap.ts new file mode 100644 index 0000000..b8e85d7 --- /dev/null +++ b/src/__tests__/MinHeap.ts @@ -0,0 +1,30 @@ +import MinHeap from "@code/MinHeap"; + +test("min heap", function () { + const heap = new MinHeap(); + + expect(heap.length).toEqual(0); + + heap.insert(5); + heap.insert(3); + heap.insert(69); + heap.insert(420); + heap.insert(4); + heap.insert(1); + heap.insert(8); + heap.insert(7); + + expect(heap.length).toEqual(8); + expect(heap.delete()).toEqual(1); + expect(heap.delete()).toEqual(3); + expect(heap.delete()).toEqual(4); + expect(heap.delete()).toEqual(5); + expect(heap.length).toEqual(4); + expect(heap.delete()).toEqual(7); + expect(heap.delete()).toEqual(8); + expect(heap.delete()).toEqual(69); + expect(heap.delete()).toEqual(420); + expect(heap.length).toEqual(8); +}); + +