mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Add Queue.
This commit is contained in:
51
src/data-structures/queue/__test__/Queue.test.js
Normal file
51
src/data-structures/queue/__test__/Queue.test.js
Normal file
@@ -0,0 +1,51 @@
|
||||
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 add data to queue', () => {
|
||||
const queue = new Queue();
|
||||
|
||||
queue.add(1);
|
||||
queue.add(2);
|
||||
|
||||
expect(queue.linkedList.toString()).toBe('1,2');
|
||||
});
|
||||
|
||||
it('should peek data from queue', () => {
|
||||
const queue = new Queue();
|
||||
|
||||
expect(queue.peek()).toBeNull();
|
||||
|
||||
queue.add(1);
|
||||
queue.add(2);
|
||||
|
||||
expect(queue.peek()).toBe(2);
|
||||
expect(queue.peek()).toBe(2);
|
||||
});
|
||||
|
||||
it('should check if queue is empty', () => {
|
||||
const queue = new Queue();
|
||||
|
||||
expect(queue.isEmpty()).toBeTruthy();
|
||||
|
||||
queue.add(1);
|
||||
|
||||
expect(queue.isEmpty()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should remove from empty', () => {
|
||||
const queue = new Queue();
|
||||
|
||||
queue.add(1);
|
||||
queue.add(2);
|
||||
|
||||
expect(queue.remove()).toBe(2);
|
||||
expect(queue.remove()).toBe(1);
|
||||
expect(queue.isEmpty()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user