UNPKG

priority-queue-with-custom-comparator

Version:

Priority queue data structure where you are able to set your own compare function.

42 lines (41 loc) 1.79 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const queue_1 = __importDefault(require("../src/queue")); const test_helper_1 = require("./test.helper"); test('initial state (created with initialElements) and no elements added', () => { const numberPriorityQueue = new queue_1.default({ comparator: test_helper_1.defaultMaxComparator, initialElements: [3, 1], }); expect(numberPriorityQueue.size()).toBe(2); }); test('initial state (created without initialElements) and no elements added', () => { const numberPriorityQueue = new queue_1.default({ comparator: test_helper_1.defaultMaxComparator, }); expect(numberPriorityQueue.size()).toBe(0); }); test('initial state (created with initialElements) and some elements added', () => { const numberPriorityQueue = new queue_1.default({ comparator: test_helper_1.defaultMaxComparator, initialElements: [3, 1], }); expect(numberPriorityQueue.size()).toBe(2); numberPriorityQueue.push(4); expect(numberPriorityQueue.size()).toBe(3); numberPriorityQueue.pushMany([7, 8]); expect(numberPriorityQueue.size()).toBe(5); }); test('initial state (created without initialElements) and some elements added', () => { const numberPriorityQueue = new queue_1.default({ comparator: test_helper_1.defaultMaxComparator, }); expect(numberPriorityQueue.size()).toBe(0); numberPriorityQueue.push(4); expect(numberPriorityQueue.size()).toBe(1); numberPriorityQueue.pushMany([7, 8]); expect(numberPriorityQueue.size()).toBe(3); });