mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-05 16:36:41 +08:00
Fix issue #315.
This commit is contained in:
@ -51,7 +51,7 @@ describe('PriorityQueue', () => {
|
|||||||
expect(priorityQueue.poll()).toBe(5);
|
expect(priorityQueue.poll()).toBe(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be possible to change priority of internal nodes', () => {
|
it('should be possible to change priority of head node', () => {
|
||||||
const priorityQueue = new PriorityQueue();
|
const priorityQueue = new PriorityQueue();
|
||||||
|
|
||||||
priorityQueue.add(10, 1);
|
priorityQueue.add(10, 1);
|
||||||
@ -59,6 +59,8 @@ describe('PriorityQueue', () => {
|
|||||||
priorityQueue.add(100, 0);
|
priorityQueue.add(100, 0);
|
||||||
priorityQueue.add(200, 0);
|
priorityQueue.add(200, 0);
|
||||||
|
|
||||||
|
expect(priorityQueue.peek()).toBe(100);
|
||||||
|
|
||||||
priorityQueue.changePriority(100, 10);
|
priorityQueue.changePriority(100, 10);
|
||||||
priorityQueue.changePriority(10, 20);
|
priorityQueue.changePriority(10, 20);
|
||||||
|
|
||||||
@ -68,7 +70,7 @@ describe('PriorityQueue', () => {
|
|||||||
expect(priorityQueue.poll()).toBe(10);
|
expect(priorityQueue.poll()).toBe(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be possible to change priority of head node', () => {
|
it('should be possible to change priority of internal nodes', () => {
|
||||||
const priorityQueue = new PriorityQueue();
|
const priorityQueue = new PriorityQueue();
|
||||||
|
|
||||||
priorityQueue.add(10, 1);
|
priorityQueue.add(10, 1);
|
||||||
@ -76,6 +78,8 @@ describe('PriorityQueue', () => {
|
|||||||
priorityQueue.add(100, 0);
|
priorityQueue.add(100, 0);
|
||||||
priorityQueue.add(200, 0);
|
priorityQueue.add(200, 0);
|
||||||
|
|
||||||
|
expect(priorityQueue.peek()).toBe(100);
|
||||||
|
|
||||||
priorityQueue.changePriority(200, 10);
|
priorityQueue.changePriority(200, 10);
|
||||||
priorityQueue.changePriority(10, 20);
|
priorityQueue.changePriority(10, 20);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user