-
Notifications
You must be signed in to change notification settings - Fork 5
/
Queue.test.js
62 lines (44 loc) · 1.3 KB
/
Queue.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Queue from '../Queue';
describe('Queue', () => {
it('should create empty queue', () => {
const queue = new Queue();
expect(queue).not.toBeNull();
expect(queue.store).not.toBeNull();
});
it('should enqueue data to queue', () => {
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
expect(queue.toString()).toBe('1,2');
});
it('should be possible to enqueue/dequeue in order', () => {
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
expect(queue.dequeue()).toBe(1);
expect(queue.dequeue()).toBe(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.dequeue()).toBeNull();
expect(queue.isEmpty()).toBeTruthy();
});
});