File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ const LinkedList = require ( '../linked-list/linkedlist' ) ;
2+
3+ class Stack {
4+ constructor ( ) {
5+ this . list = new LinkedList ( ) ;
6+ }
7+
8+ push ( data ) {
9+ this . list . addLast ( data ) ;
10+ }
11+
12+ pop ( ) {
13+ return this . list . removeLast ( ) ;
14+ }
15+ }
16+
17+ module . exports = Stack ;
Original file line number Diff line number Diff line change 1+ const expect = require ( 'chai' ) . expect ;
2+ const Stack = require ( './stack' ) ;
3+
4+ describe ( 'Stacks: QueueViaStack' , function ( ) {
5+ let stack ;
6+
7+ beforeEach ( function ( ) {
8+ stack = new Stack ( ) ;
9+ } ) ;
10+
11+ describe ( '.add' , function ( ) {
12+ it ( 'should hold an element' , function ( ) {
13+ stack . push ( 1 ) ;
14+ expect ( stack . list . head . data ) . to . equal ( 1 ) ;
15+ } ) ;
16+ } ) ;
17+
18+ describe ( '.remove' , function ( ) {
19+ it ( 'should handle removing from empty stack' , function ( ) {
20+ expect ( stack . pop ( ) ) . to . equal ( undefined ) ;
21+ } ) ;
22+
23+ it ( 'should remove an element' , function ( ) {
24+ stack . push ( 1 ) ;
25+ expect ( stack . pop ( ) ) . to . equal ( 1 ) ;
26+ } ) ;
27+ } ) ;
28+
29+ } ) ;
You can’t perform that action at this time.
0 commit comments