Skip to content

Commit 447f690

Browse files
authored
tests: added stack unit tests (#398)
Signed-off-by: Anthony D. Mays <[email protected]>
1 parent 0837e2e commit 447f690

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Stack } from './stack.js';
2+
3+
describe('Stack', () => {
4+
test('testPush', () => {
5+
const stack = new Stack();
6+
stack.push(1);
7+
expect(stack.peek()).toBe(1);
8+
});
9+
10+
test('testPop', () => {
11+
const stack = new Stack();
12+
stack.push(1);
13+
stack.push(2);
14+
expect(stack.pop()).toBe(2);
15+
expect(stack.pop()).toBe(1);
16+
});
17+
18+
test('testTop', () => {
19+
const stack = new Stack();
20+
stack.push(1);
21+
stack.push(2);
22+
expect(stack.peek()).toBe(2);
23+
stack.pop();
24+
expect(stack.peek()).toBe(1);
25+
});
26+
27+
test('testIsEmpty', () => {
28+
const stack = new Stack();
29+
expect(stack.isEmpty()).toBe(true);
30+
stack.push(1);
31+
expect(stack.isEmpty()).toBe(false);
32+
stack.pop();
33+
expect(stack.isEmpty()).toBe(true);
34+
});
35+
36+
test('testTopEmptyStack', () => {
37+
const stack = new Stack();
38+
expect(() => stack.peek()).toThrow();
39+
});
40+
});

0 commit comments

Comments
 (0)