File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Stack } from './stack.js' ;
2+
3+ describe ( 'Stack' , ( ) => {
4+ test ( 'testPush' , ( ) => {
5+ const stack = new Stack ( ) ;
6+ stack . push ( 1 ) ;
7+ expect ( stack . peek ( ) ) . toBe ( 1 ) ;
8+ } ) ;
9+
10+ test ( 'testPop' , ( ) => {
11+ const stack = new Stack ( ) ;
12+ stack . push ( 1 ) ;
13+ stack . push ( 2 ) ;
14+ expect ( stack . pop ( ) ) . toBe ( 2 ) ;
15+ expect ( stack . pop ( ) ) . toBe ( 1 ) ;
16+ } ) ;
17+
18+ test ( 'testTop' , ( ) => {
19+ const stack = new Stack ( ) ;
20+ stack . push ( 1 ) ;
21+ stack . push ( 2 ) ;
22+ expect ( stack . peek ( ) ) . toBe ( 2 ) ;
23+ stack . pop ( ) ;
24+ expect ( stack . peek ( ) ) . toBe ( 1 ) ;
25+ } ) ;
26+
27+ test ( 'testIsEmpty' , ( ) => {
28+ const stack = new Stack ( ) ;
29+ expect ( stack . isEmpty ( ) ) . toBe ( true ) ;
30+ stack . push ( 1 ) ;
31+ expect ( stack . isEmpty ( ) ) . toBe ( false ) ;
32+ stack . pop ( ) ;
33+ expect ( stack . isEmpty ( ) ) . toBe ( true ) ;
34+ } ) ;
35+
36+ test ( 'testTopEmptyStack' , ( ) => {
37+ const stack = new Stack ( ) ;
38+ expect ( ( ) => stack . peek ( ) ) . toThrow ( ) ;
39+ } ) ;
40+ } ) ;
You can’t perform that action at this time.
0 commit comments