Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0_numberStack - test and implementation #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions ts-testing-training/src/0_numberStack/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
describe('Stack', () => {
it('should do stuff', () => {
// do stuff!
import {NumberStack} from './index';

describe('NumberStack', () => {
let testSubject: NumberStack;
beforeEach(() => {
testSubject = new NumberStack();
});

it('should not return a value after push call', () => {
expect(testSubject.push(10)).toBe(undefined);
});

it('should return the last pushed value on pop() call', () => {
testSubject.push(10);
testSubject.push(5.5);

expect(testSubject.pop()).toStrictEqual(5.5);
});

it('should return the correct value after subsequent pop() calls', () => {
testSubject.push(10);
testSubject.push(5.5);

testSubject.pop();
expect(testSubject.pop()).toStrictEqual(10);
});

it('should return the contents by accessing the contents property', () => {
testSubject.push(10);
testSubject.push(5.5);
const result = testSubject.contents;
expect(result.length).toStrictEqual(2);
});

it('should return the last inserted value on top', () => {
testSubject.push(10);
testSubject.push(5.5);

expect(testSubject.top).toStrictEqual(5.5);
});

it('should return the same value after subsequent top() calls', () => {
testSubject.push(10);
testSubject.push(5.5);

expect(testSubject.top).toStrictEqual(testSubject.top);
});
});
12 changes: 6 additions & 6 deletions ts-testing-training/src/0_numberStack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ export class NumberStack {

/** Puts a number on the top of the stack */
public push(input: number): void {
return;
this.list.push(input);
}

/** Remove the most recently pushed number from the stack and return it */
public pop(): number {
return 0;
public pop(): number | undefined {
return this.list.pop();
}

/**
* Returns the most recently pushed number in the stack. Does not modify the
* contents of the stack itself
*/
get top(): number {
return 0;
get top(): number | undefined {
return this.list[this.list.length-1];
}

/** Returns all the contents of the stack */
get contents(): number[] {
return [];
return this.list;
}
}
Loading