mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
import Queue from '../Queue';
|
|
|
|
describe('Queue', () => {
|
|
it('should create empty queue', () => {
|
|
const queue = new Queue();
|
|
expect(queue).not.toBeNull();
|
|
expect(queue.linkedList).not.toBeNull();
|
|
});
|
|
|
|
it('should enqueue data to queue', () => {
|
|
const queue = new Queue();
|
|
|
|
queue.enqueue(1);
|
|
queue.enqueue(2);
|
|
|
|
expect(queue.linkedList.toString()).toBe('1,2');
|
|
});
|
|
|
|
it('should peek data from queue', () => {
|
|
const queue = new Queue();
|
|
|
|
expect(queue.peek()).toBeNull();
|
|
|
|
queue.enqueue(1);
|
|
queue.enqueue(2);
|
|
|
|
expect(queue.peek()).toBe(1);
|
|
expect(queue.peek()).toBe(1);
|
|
});
|
|
|
|
it('should check if queue is empty', () => {
|
|
const queue = new Queue();
|
|
|
|
expect(queue.isEmpty()).toBeTruthy();
|
|
|
|
queue.enqueue(1);
|
|
|
|
expect(queue.isEmpty()).toBeFalsy();
|
|
});
|
|
|
|
it('should dequeue from queue in FIFO order', () => {
|
|
const queue = new Queue();
|
|
|
|
queue.enqueue(1);
|
|
queue.enqueue(2);
|
|
|
|
expect(queue.dequeue()).toBe(1);
|
|
expect(queue.dequeue()).toBe(2);
|
|
expect(queue.isEmpty()).toBeTruthy();
|
|
});
|
|
});
|