-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpq.test.ts
More file actions
27 lines (23 loc) · 721 Bytes
/
pq.test.ts
File metadata and controls
27 lines (23 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import {PriorityQueue} from './pq';
const numCmp = (x: number, y: number) => (y > x ? 1 : x === y ? 0 : -1);
test('priority queue supports inserts', () => {
const pq = new PriorityQueue(numCmp);
expect(pq.length()).toBe(0);
pq.insert(1);
expect(pq.length()).toBe(1);
pq.insert(2);
expect(pq.length()).toBe(2);
});
test('priority queue supports popping the min', () => {
const pq = new PriorityQueue(numCmp);
pq.insert(2);
pq.insert(1);
pq.insert(3);
expect(pq.popMin()).toBe(1);
expect(pq.popMin()).toBe(2);
expect(pq.popMin()).toBe(3);
});
test('priority queue throws on empty', () => {
const pq = new PriorityQueue<number>(numCmp);
expect(() => pq.popMin()).toThrowError(/empty/);
});