Skip to content

Commit a13cd61

Browse files
committed
fixes #31
Adds tests for custom heaps and comparators
1 parent 027435f commit a13cd61

File tree

6 files changed

+152
-79
lines changed

6 files changed

+152
-79
lines changed

src/Heap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ export class Heap<T> implements Iterable<T> {
690690
const self = this.heapArray[i];
691691

692692
const getPotentialParent = (best: number, j: number) => {
693-
if (this.compare(this.heapArray[j], this.heapArray[best]) < 0) {
693+
if (this.heapArray.length > j && this.compare(this.heapArray[j], this.heapArray[best]) < 0) {
694694
best = j;
695695
}
696696
return best;

tests/heap-private-methods.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Heap from '../src/Heap';
2-
3-
const someValues = [3, 15, 2, 300, 16, 4, 1, 8, 50, 21, 58, 7, 4, 9, 78, 88];
4-
const otherValues = [12, 1, 2, 30, 116, 42, 12, 18, 1, 1, 1, 1];
2+
import { someValues } from './test-helpers';
53

64
describe('Heap private', function () {
75
const heaps = [

0 commit comments

Comments
 (0)