-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"collectCoverageFrom": [ | ||
"<rootDir>/src/**/*.ts", | ||
"!<rootDir>/src/**/*/index.ts" | ||
"!<rootDir>/src/**/*/index.ts", | ||
"!<rootDir>/src/index.ts" | ||
], | ||
"preset": "ts-jest" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,58 @@ | ||
import { Stack } from "./stack"; | ||
|
||
describe("class Stack", () => { | ||
it("should throw an exception if attempting to remove item from empty stack", () => { | ||
const stack = new Stack(); | ||
describe("empty()", () => { | ||
it("should return `true` when the stack is empty", () => | ||
expect(new Stack().empty()).toBe(true)); | ||
|
||
expect(() => stack.pop()).toThrowError(); | ||
it("should return `false` when the stack is not empty", () => { | ||
const stack = new Stack(); | ||
|
||
stack.push("test"); | ||
|
||
expect(stack.empty()).toBe(false); | ||
}); | ||
}); | ||
|
||
it("should throw an exception if attempting to access item from empty stack", () => { | ||
const stack = new Stack(); | ||
describe("push()", () => { | ||
it("should insert elements into the stack", () => { | ||
const stack = new Stack(); | ||
|
||
stack.push("foo"); | ||
stack.push("bar"); | ||
|
||
expect(stack).toHaveProperty(["elements", 0], "foo"); | ||
expect(stack).toHaveProperty(["elements", 1], "bar"); | ||
}); | ||
}); | ||
|
||
describe("pop()", () => { | ||
it("should throw error if the stack is empty", () => | ||
expect(() => new Stack().pop()).toThrow()); | ||
|
||
it("should remove and return the top element from the stack", () => { | ||
const stack = new Stack(); | ||
|
||
stack.push("foo"); | ||
stack.push("bar"); | ||
|
||
expect(stack.pop()).toBe("bar"); | ||
expect(stack).toHaveProperty(["elements", "length"], 1); | ||
}); | ||
}); | ||
|
||
describe("top()", () => { | ||
it("should throw error if the stack is empty", () => | ||
expect(() => new Stack().top()).toThrow()); | ||
|
||
it("should return the top element from the stack", () => { | ||
const stack = new Stack(); | ||
|
||
stack.push("foo"); | ||
stack.push("bar"); | ||
|
||
expect(() => stack.top()).toThrowError(); | ||
expect(stack.top()).toBe("bar"); | ||
expect(stack).toHaveProperty(["elements", "length"], 2); | ||
}); | ||
}); | ||
}); |