-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.test.ts
More file actions
29 lines (23 loc) · 719 Bytes
/
Stack.test.ts
File metadata and controls
29 lines (23 loc) · 719 Bytes
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
import { Stack } from "./Stack";
test("should create a Stack", () => {
const stack = new Stack();
expect(stack.length).toBe(0);
expect(stack.first).toBeNull();
expect(stack.last).toBeNull();
});
test("should be able to add a new value using push", () => {
const stack = new Stack();
stack.push(3);
expect(stack.first?.value).toBe(3);
expect(stack.last?.value).toBe(3);
expect(stack.length).toBe(1);
stack.push(2);
expect(stack.first?.value).toBe(2);
expect(stack.last?.value).toBe(3);
expect(stack.length).toBe(2);
stack.push(1);
expect(stack.first?.value).toBe(1);
expect(stack.first?.next?.value).toBe(2);
expect(stack.last?.value).toBe(3);
expect(stack.length).toBe(3);
});