1+ var assert = require ( 'assert' ) ;
2+ const { stacks } = require ( '../index' ) ;
3+
4+ describe ( 'Stack' , function ( ) {
5+ it ( 'should make a new stack' , function ( ) {
6+ const stack = new stacks . Stack ( ) ;
7+ assert . equal ( stack . height ( ) , 0 ) ;
8+ } ) ;
9+
10+ it ( 'should push an item on to the stack' , function ( ) {
11+ let stack = new stacks . Stack ( ) ;
12+ stack . push ( 'item' ) ;
13+
14+ assert . equal ( stack . peek ( ) , 'item' ) ;
15+ } ) ;
16+
17+ it ( 'should pop an item off the stack' , function ( ) {
18+ let stack = new stacks . Stack ( ) ;
19+ stack . push ( 'item' ) ;
20+ let value = stack . pop ( ) ;
21+ assert . equal ( value , 'item' ) ;
22+ } ) ;
23+
24+ it ( 'should push three items on and pop them off in order' , function ( ) {
25+ let stack = new stacks . Stack ( ) ;
26+ stack . push ( 'item1' ) ;
27+ stack . push ( 'item2' ) ;
28+ stack . push ( 'item3' ) ;
29+
30+ let value = stack . pop ( ) ;
31+ assert . equal ( value , 'item3' ) ;
32+
33+ value = stack . pop ( ) ;
34+ assert . equal ( value , 'item2' ) ;
35+
36+ value = stack . pop ( ) ;
37+ assert . equal ( value , 'item1' ) ;
38+ } ) ;
39+ } ) ;
40+
41+ describe ( 'Array Stack' , function ( ) {
42+ it ( 'should make a new stack' , function ( ) {
43+ const stack = new stacks . ArrayStack ( ) ;
44+ assert . equal ( stack . height ( ) , 0 ) ;
45+ } ) ;
46+
47+ it ( 'should push an item on to the stack' , function ( ) {
48+ let stack = new stacks . ArrayStack ( ) ;
49+ stack . push ( 'item' ) ;
50+
51+ assert . equal ( stack . peek ( ) , 'item' ) ;
52+ } ) ;
53+
54+ it ( 'should pop an item off the stack' , function ( ) {
55+ let stack = new stacks . ArrayStack ( ) ;
56+ stack . push ( 'item' ) ;
57+ let value = stack . pop ( ) ;
58+ assert . equal ( value , 'item' ) ;
59+ } ) ;
60+
61+ it ( 'should push three items on and pop them off in order' , function ( ) {
62+ let stack = new stacks . ArrayStack ( ) ;
63+ stack . push ( 'item1' ) ;
64+ stack . push ( 'item2' ) ;
65+ stack . push ( 'item3' ) ;
66+
67+ let value = stack . pop ( ) ;
68+ assert . equal ( value , 'item3' ) ;
69+
70+ value = stack . pop ( ) ;
71+ assert . equal ( value , 'item2' ) ;
72+
73+ value = stack . pop ( ) ;
74+ assert . equal ( value , 'item1' ) ;
75+ } ) ;
76+ } ) ;
0 commit comments