@@ -4,9 +4,12 @@ const LinkedList = require('./linkedlist');
44describe ( 'LinkedList' , function ( ) {
55 let list ;
66
7+ beforeEach ( function ( ) {
8+ list = new LinkedList ( ) ;
9+ } ) ;
10+
711 describe ( '.addLast' , function ( ) {
812 beforeEach ( function ( ) {
9- list = new LinkedList ( ) ;
1013 list . addLast ( 1 ) ;
1114 list . addLast ( 2 ) ;
1215 list . addLast ( 3 ) ;
@@ -37,7 +40,6 @@ describe('LinkedList', function () {
3740
3841 describe ( '.addFirst' , function ( ) {
3942 beforeEach ( function ( ) {
40- list = new LinkedList ( ) ;
4143 list . addFirst ( 1 ) ;
4244 list . addFirst ( 2 ) ;
4345 list . addFirst ( 3 ) ;
@@ -71,6 +73,32 @@ describe('LinkedList', function () {
7173 } ) ;
7274 } ) ;
7375
76+ describe ( '.removeLast' , function ( ) {
77+ it ( 'should handle empty' , function ( ) {
78+ expect ( list . removeLast ( ) ) . to . equal ( undefined ) ;
79+ } ) ;
80+
81+ it ( 'should remove item' , function ( ) {
82+ list . add ( 1 ) ;
83+ expect ( list . removeLast ( ) ) . to . equal ( 1 ) ;
84+ } ) ;
85+
86+ it ( 'should remove multiple items' , function ( ) {
87+ list . addLast ( 1 ) ;
88+ list . addLast ( 2 ) ;
89+
90+ expect ( list . removeLast ( ) ) . to . equal ( 2 ) ;
91+ expect ( list . tail . data ) . to . equal ( 1 ) ;
92+ expect ( list . head . data ) . to . equal ( 1 ) ;
93+ expect ( list . size ( ) ) . to . equal ( 1 ) ;
94+
95+ expect ( list . removeLast ( ) ) . to . equal ( 1 ) ;
96+ expect ( list . tail ) . to . equal ( null ) ;
97+ expect ( list . head ) . to . equal ( null ) ;
98+ expect ( list . size ( ) ) . to . equal ( 0 ) ;
99+ } ) ;
100+ } ) ;
101+
74102 describe ( '.delete' , function ( ) {
75103 beforeEach ( function ( ) {
76104 list = new LinkedList ( ) ;
0 commit comments