feat: heap tests
This commit is contained in:
parent
7ffe2a8193
commit
b83a3f379b
2 changed files with 31 additions and 1 deletions
|
|
@ -38,7 +38,7 @@ module.exports = {
|
||||||
MinHeap: {
|
MinHeap: {
|
||||||
type: "class",
|
type: "class",
|
||||||
methods: [{
|
methods: [{
|
||||||
name: "push",
|
name: "insert",
|
||||||
args: "value: number",
|
args: "value: number",
|
||||||
return: "void",
|
return: "void",
|
||||||
}, {
|
}, {
|
||||||
|
|
|
||||||
30
src/__tests__/MinHeap.ts
Normal file
30
src/__tests__/MinHeap.ts
Normal file
|
|
@ -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);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue