Skip to content

Commit

Permalink
Merge c0b3fb6 into db6c0b4
Browse files Browse the repository at this point in the history
  • Loading branch information
ycliu0953 committed Jan 3, 2019
2 parents db6c0b4 + c0b3fb6 commit 33ab2b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/data_structures/stack.js
Expand Up @@ -28,6 +28,10 @@ class Stack {
peek() {
return this.isEmpty() ? null : internal(this).array[this.size() - 1];
}

toString() {
return this.isEmpty() ? '' : internal(this).array.toString();
}
}

module.exports = Stack;
16 changes: 16 additions & 0 deletions test/data_structures/stack.test.js
Expand Up @@ -65,4 +65,20 @@ describe('# Stack', () => {
should(stack.pop()).be.Null();
});
});

describe('toString', () => {
it('should return empty string if stack is empty', () => {
const stack = new Stack();
stack.toString().should.be.equal('');
});

it('should return the same format as Array.toString()', () => {
const array = ['Javascript', 'Data', 'Structure'];
const stack = new Stack();
array.forEach((elem) => {
stack.push(elem);
});
stack.toString().should.be.equal(array.toString());
});
});
});

0 comments on commit 33ab2b4

Please sign in to comment.