Skip to content

Commit 377b73d

Browse files
author
K Hudson
committed
Add stack test suite.
0 parents  commit 377b73d

File tree

7 files changed

+4970
-0
lines changed

7 files changed

+4970
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
built
2+
node_modules
3+
.idea

package-lock.json

Lines changed: 4871 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "data-structures-ts",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"test": "jest"
9+
},
10+
"jest": {
11+
"transform": {
12+
".(ts|tsx)": "ts-jest"
13+
},
14+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
15+
"moduleFileExtensions": [
16+
"ts",
17+
"tsx",
18+
"js"
19+
]
20+
},
21+
"keywords": [],
22+
"author": "",
23+
"license": "ISC",
24+
"dependencies": {
25+
"typescript": "^4.2.3"
26+
},
27+
"devDependencies": {
28+
"@types/jest": "^26.0.22",
29+
"jest": "^26.6.3",
30+
"ts-jest": "^26.5.4"
31+
}
32+
}

src/Node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default class Node {}

src/Stack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default class Stack {}

tests/Stack.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import Stack from "../src/Stack";
2+
import Node from "../src/Node";
3+
4+
test("Smoke test ...", () => {
5+
expect(true).toEqual(true);
6+
});
7+
8+
describe("Stack", () => {
9+
let stack: Stack;
10+
11+
beforeEach(() => {
12+
stack = new Stack();
13+
})
14+
15+
test("should be empty on instantiation", () => {
16+
expect(stack.isEmpty()).toBeTruthy()
17+
});
18+
19+
test("push() should add a node", () => {
20+
let node: Node = new Node();
21+
stack.push(node);
22+
expect(stack.isEmpty()).toBeFalsy();
23+
});
24+
25+
test("count() should count its nodes", () => {
26+
let node: Node = new Node();
27+
stack.push(node);
28+
stack.push(node);
29+
expect(stack.count()).toEqual(2);
30+
});
31+
32+
test("pop() should remove the last node added", () => {
33+
let node1: Node = new Node();
34+
let node2: Node = new Node();
35+
stack.push(node1);
36+
stack.push(node2);
37+
let lastNode = stack.pop();
38+
expect(lastNode).toEqual(node2);
39+
});
40+
41+
test("peek() should return the top node", () => {
42+
let node1: Node = new Node();
43+
let node2: Node = new Node();
44+
stack.push(node1);
45+
stack.push(node2);
46+
expect(stack.peek()).toEqual(node2);
47+
});
48+
})

tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./built",
4+
"allowJs": true,
5+
"target": "es5",
6+
"module": "ES2015",
7+
"lib": ["es2015"],
8+
"strict": true,
9+
"declaration": true,
10+
"sourceMap": true
11+
},
12+
"include": ["./src/**/*"],
13+
"exclude": ["node_modules", "**/*.test.ts"]
14+
}

0 commit comments

Comments
 (0)