-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathStack.test.js
More file actions
43 lines (36 loc) · 1.06 KB
/
Stack.test.js
File metadata and controls
43 lines (36 loc) · 1.06 KB
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
const Stack = require('../../src/dataStructures/Stack');
describe('Stack data structure', () => {
it ('Should have empty stack when instantiated', () => {
const stack = new Stack();
expect(stack.top).toBe(0);
expect(stack.dataStore.length).toBe(0);
});
it('Should add the first item on top', () => {
const stack = new Stack();
stack.push(1);
expect(stack.dataStore.toString()).toBe('1');
});
it('Should remove items from the top of the stack', () => {
const stack = new Stack();
stack.push(1)
stack.push(2)
stack.push(3)
expect(stack.pop()).toBe(3);
expect(stack.pop()).toBe(2);
expect(stack.pop()).toBe(1);
});
it('Should print a correct representation of the stack as string', () => {
const stack = new Stack();
stack.push(1);
stack.push(2);
stack.push(3);
expect(stack.dataStore.toString()).toBe('1,2,3');
});
it('Should peek top element from stack', () => {
const stack = new Stack();
stack.push(1);
stack.push(2);
stack.push(3);
expect(stack.peek()).toBe(3);
});
})