heap-typed
Advanced tools
Comparing version 1.34.3 to 1.34.4
@@ -1,1 +0,2 @@ | ||
{} | ||
{"/Users/revone/projects/data-structure-typed-individuals/heap-typed/src/index.ts": {"path":"/Users/revone/projects/data-structure-typed-individuals/heap-typed/src/index.ts","statementMap":{"0":{"start":{"line":8,"column":0},"end":{"line":8,"column":9}},"1":{"start":{"line":8,"column":9},"end":{"line":8,"column":19}},"2":{"start":{"line":8,"column":19},"end":{"line":8,"column":25}},"3":{"start":{"line":8,"column":25},"end":{"line":8,"column":34}},"4":{"start":{"line":8,"column":34},"end":{"line":8,"column":72}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":8,"column":9},"end":{"line":8,"column":17}},"loc":{"start":{"line":8,"column":9},"end":{"line":8,"column":19}}},"1":{"name":"(anonymous_1)","decl":{"start":{"line":8,"column":19},"end":{"line":8,"column":23}},"loc":{"start":{"line":8,"column":19},"end":{"line":8,"column":25}}},"2":{"name":"(anonymous_2)","decl":{"start":{"line":8,"column":25},"end":{"line":8,"column":32}},"loc":{"start":{"line":8,"column":25},"end":{"line":8,"column":34}}},"3":{"name":"(anonymous_3)","decl":{"start":{"line":8,"column":34},"end":{"line":8,"column":41}},"loc":{"start":{"line":8,"column":34},"end":{"line":8,"column":72}}}},"branchMap":{},"s":{"0":1,"1":1,"2":1,"3":2,"4":3},"f":{"0":0,"1":0,"2":1,"3":2},"b":{}} | ||
} |
@@ -1,2 +0,3 @@ | ||
{"total": {"lines":{"total":0,"covered":0,"skipped":0,"pct":"Unknown"},"statements":{"total":0,"covered":0,"skipped":0,"pct":"Unknown"},"functions":{"total":0,"covered":0,"skipped":0,"pct":"Unknown"},"branches":{"total":0,"covered":0,"skipped":0,"pct":"Unknown"},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":"Unknown"}} | ||
{"total": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":5,"covered":5,"skipped":0,"pct":100},"functions":{"total":4,"covered":2,"skipped":0,"pct":50},"branches":{"total":0,"covered":0,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":"Unknown"}} | ||
,"/Users/revone/projects/data-structure-typed-individuals/heap-typed/src/index.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":4,"covered":2,"skipped":0,"pct":50},"statements":{"total":5,"covered":5,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} | ||
} |
{ | ||
"name": "heap-typed", | ||
"version": "1.34.3", | ||
"version": "1.34.4", | ||
"description": "Heap. Javascript & Typescript Data Structure.", | ||
@@ -133,4 +133,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"data-structure-typed": "^1.34.3" | ||
"data-structure-typed": "^1.34.4" | ||
} | ||
} |
@@ -1,5 +0,55 @@ | ||
describe('Operation Test', () => { | ||
it('should perform various operations well', () => { | ||
expect(true).toBeTruthy(); | ||
import {MinHeap, MaxHeap} from '../src'; | ||
describe('Heap Operation Test', () => { | ||
it('should numeric heap work well', function () { | ||
const minNumHeap = new MinHeap<number>(); | ||
minNumHeap.add(1).add(6).add(2).add(0).add(5).add(9); | ||
expect(minNumHeap.has(1)).toBe(true); | ||
expect(minNumHeap.has(2)).toBe(true); | ||
expect(minNumHeap.poll()).toBe(0); | ||
expect(minNumHeap.poll()).toBe(1); | ||
expect(minNumHeap.peek()).toBe(2); | ||
expect(!minNumHeap.has(1)); | ||
expect(minNumHeap.has(2)); | ||
const arrFromHeap = minNumHeap.toArray(); | ||
expect(arrFromHeap.length).toBe(4); | ||
expect(arrFromHeap[0]).toBe(2); | ||
expect(arrFromHeap[1]).toBe(5); | ||
expect(arrFromHeap[2]).toBe(9); | ||
expect(arrFromHeap[3]).toBe(6); | ||
expect(minNumHeap.sort()).toEqual([2, 5, 6, 9]); | ||
}); | ||
it('should object heap work well', function () { | ||
const minHeap = new MinHeap<{a: string}>(); | ||
minHeap.add(1, {a: 'a1'}); | ||
minHeap.add(6, {a: 'a6'}); | ||
minHeap.add(2, {a: 'a2'}); | ||
minHeap.add(0, {a: 'a0'}); | ||
expect(minHeap.peek()).toEqual({a: 'a0'}); | ||
expect(minHeap.toArray()).toEqual([{a: 'a0'}, {a: 'a1'}, {a: 'a2'}, {a: 'a6'}]); | ||
let i = 0; | ||
const expectPolled = [{a: 'a0'}, {a: 'a1'}, {a: 'a2'}, {a: 'a6'}]; | ||
while (minHeap.size > 0) { | ||
expect(minHeap.poll()).toEqual(expectPolled[i]); | ||
i++; | ||
} | ||
const maxHeap = new MaxHeap<{a: string}>(); | ||
maxHeap.add(1, {a: 'a1'}); | ||
maxHeap.add(6, {a: 'a6'}); | ||
maxHeap.add(5, {a: 'a5'}); | ||
maxHeap.add(2, {a: 'a2'}); | ||
maxHeap.add(0, {a: 'a0'}); | ||
maxHeap.add(9, {a: 'a9'}); | ||
expect(maxHeap.peek()).toEqual({a: 'a9'}); | ||
expect(maxHeap.toArray()).toEqual([{a: 'a9'}, {a: 'a2'}, {a: 'a6'}, {a: 'a1'}, {a: 'a0'}, {a: 'a5'}]); | ||
const maxExpectPolled = [{a: 'a9'}, {a: 'a6'}, {a: 'a5'}, {a: 'a2'}, {a: 'a1'}, {a: 'a0'}]; | ||
let maxI = 0; | ||
while (maxHeap.size > 0) { | ||
expect(maxHeap.poll()).toEqual(maxExpectPolled[maxI]); | ||
maxI++; | ||
} | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
498822
38
2770
Updateddata-structure-typed@^1.34.4