UNPKG

priority-queue-with-custom-comparator

Version:

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

82 lines (81 loc) 3.92 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 none added', () => { const numberPriorityQueue = new queue_1.default({ comparator: test_helper_1.defaultMaxComparator, initialElements: [2, 3, 1], }); expect(numberPriorityQueue.has(5)).toBe(false); expect(numberPriorityQueue.has(2)).toBe(true); expect(numberPriorityQueue.has(3)).toBe(true); expect(numberPriorityQueue.has(1)).toBe(true); expect(numberPriorityQueue.has(9)).toBe(false); expect(numberPriorityQueue.has(0)).toBe(false); expect(numberPriorityQueue.has(-1)).toBe(false); }); test('initial state (created with initialElements) and some added', () => { const numberPriorityQueue = new queue_1.default({ comparator: test_helper_1.defaultMaxComparator, initialElements: [2, 3, 1], }); expect(numberPriorityQueue.has(5)).toBe(false); expect(numberPriorityQueue.has(2)).toBe(true); expect(numberPriorityQueue.has(3)).toBe(true); expect(numberPriorityQueue.has(1)).toBe(true); expect(numberPriorityQueue.has(9)).toBe(false); expect(numberPriorityQueue.has(0)).toBe(false); expect(numberPriorityQueue.has(-1)).toBe(false); numberPriorityQueue.push(5); expect(numberPriorityQueue.has(5)).toBe(true); expect(numberPriorityQueue.has(2)).toBe(true); expect(numberPriorityQueue.has(3)).toBe(true); expect(numberPriorityQueue.has(1)).toBe(true); expect(numberPriorityQueue.has(9)).toBe(false); expect(numberPriorityQueue.has(0)).toBe(false); expect(numberPriorityQueue.has(-1)).toBe(false); }); test('initial state (created without initialElements) and none added', () => { const numberPriorityQueue = new queue_1.default({ comparator: test_helper_1.defaultMaxComparator, }); expect(numberPriorityQueue.has(5)).toBe(false); expect(numberPriorityQueue.has(2)).toBe(false); expect(numberPriorityQueue.has(3)).toBe(false); expect(numberPriorityQueue.has(1)).toBe(false); expect(numberPriorityQueue.has(9)).toBe(false); expect(numberPriorityQueue.has(0)).toBe(false); expect(numberPriorityQueue.has(-1)).toBe(false); }); test('initial state (created without initialElements) and some added', () => { const numberPriorityQueue = new queue_1.default({ comparator: test_helper_1.defaultMaxComparator, }); expect(numberPriorityQueue.has(5)).toBe(false); expect(numberPriorityQueue.has(2)).toBe(false); expect(numberPriorityQueue.has(3)).toBe(false); expect(numberPriorityQueue.has(1)).toBe(false); expect(numberPriorityQueue.has(9)).toBe(false); expect(numberPriorityQueue.has(0)).toBe(false); expect(numberPriorityQueue.has(-1)).toBe(false); numberPriorityQueue.push(5); expect(numberPriorityQueue.has(5)).toBe(true); expect(numberPriorityQueue.has(2)).toBe(false); expect(numberPriorityQueue.has(3)).toBe(false); expect(numberPriorityQueue.has(1)).toBe(false); expect(numberPriorityQueue.has(9)).toBe(false); expect(numberPriorityQueue.has(0)).toBe(false); expect(numberPriorityQueue.has(-1)).toBe(false); numberPriorityQueue.push(-1); expect(numberPriorityQueue.has(5)).toBe(true); expect(numberPriorityQueue.has(2)).toBe(false); expect(numberPriorityQueue.has(3)).toBe(false); expect(numberPriorityQueue.has(1)).toBe(false); expect(numberPriorityQueue.has(9)).toBe(false); expect(numberPriorityQueue.has(0)).toBe(false); expect(numberPriorityQueue.has(-1)).toBe(true); });