-
Notifications
You must be signed in to change notification settings - Fork 269
/
immitate-queue-using-stack.test.js
57 lines (46 loc) · 1.31 KB
/
immitate-queue-using-stack.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
const Queue = require('.');
describe('Immitated Queue using 2 Stacks', () => {
it('Should be class', () => {
expect(typeof Queue.prototype.constructor).toEqual('function');
});
describe('Queue API', () => {
let queue = null;
beforeEach(() => {
queue = new Queue();
});
it('Should add() element to a queue', () => {
queue.add(5);
expect(queue.data).toEqual([5]);
});
it('Should remove() an element from the queue', () => {
queue.add(2);
queue.add(3);
expect(queue.remove()).toEqual(2);
expect(queue.data).toEqual([3]);
});
describe('peek()', () => {
beforeEach(() => {
queue.add(2);
queue.add(5);
});
it('Should return the elemet to be removed using peek()', () => {
expect(queue.peek()).toEqual(2);
});
it('Should not remove the element', () => {
expect(queue.peek()).toEqual(2);
expect(queue.remove()).toEqual(2);
});
});
it('Should maintain the order of elements', () => {
// first in first out
queue.add(2);
queue.add(1);
queue.add(4);
queue.add(3);
expect(queue.remove()).toEqual(2);
expect(queue.remove()).toEqual(1);
expect(queue.remove()).toEqual(4);
expect(queue.remove()).toEqual(3);
});
});
});