diff --git a/lesson_12/structs_ts/src/stack.test.ts b/lesson_12/structs_ts/src/stack.test.ts new file mode 100644 index 000000000..d52c1a6ae --- /dev/null +++ b/lesson_12/structs_ts/src/stack.test.ts @@ -0,0 +1,40 @@ +import { Stack } from './stack.js'; + +describe('Stack', () => { + test('testPush', () => { + const stack = new Stack(); + stack.push(1); + expect(stack.peek()).toBe(1); + }); + + test('testPop', () => { + const stack = new Stack(); + stack.push(1); + stack.push(2); + expect(stack.pop()).toBe(2); + expect(stack.pop()).toBe(1); + }); + + test('testTop', () => { + const stack = new Stack(); + stack.push(1); + stack.push(2); + expect(stack.peek()).toBe(2); + stack.pop(); + expect(stack.peek()).toBe(1); + }); + + test('testIsEmpty', () => { + const stack = new Stack(); + expect(stack.isEmpty()).toBe(true); + stack.push(1); + expect(stack.isEmpty()).toBe(false); + stack.pop(); + expect(stack.isEmpty()).toBe(true); + }); + + test('testTopEmptyStack', () => { + const stack = new Stack(); + expect(() => stack.peek()).toThrow(); + }); +});