-
Notifications
You must be signed in to change notification settings - Fork 931
/
Copy pathstack.spec.js
43 lines (36 loc) · 959 Bytes
/
stack.spec.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
const { Stack } = require('../../index');
describe('Stack', () => {
let stack;
beforeEach(() => {
stack = new Stack();
});
describe('#push', () => {
it('should push an element to the stack', () => {
expect(stack.size).toEqual(0);
stack.push(1);
expect(stack.size).toEqual(1);
});
});
describe('#pop', () => {
beforeEach(() => {
stack.push('a');
stack.push('b');
});
it('should get last element entered', () => {
expect(stack.pop()).toEqual('b');
expect(stack.pop()).toEqual('a');
expect(stack.pop()).toEqual(null);
});
});
describe('#isEmpty', () => {
it('should return true when empty', () => {
// expect(stack.size).toBe(0);
expect(stack.isEmpty()).toBe(true);
});
it('should return false when not empty', () => {
stack.add('a');
// expect(stack.size).toBe(1);
expect(stack.isEmpty()).toBe(false);
});
});
});