@@ -20,10 +20,10 @@ describe('Binary Search Tree', () => {
2020 const root = bst . add ( 5 ) ;
2121 const n = bst . add ( 1 ) ;
2222 expect ( n . toValues ( ) ) . toMatchObject ( {
23- value : 1 , parent : 5 , left : undefined , right : undefined ,
23+ value : 1 , parent : 5 , left : null , right : null ,
2424 } ) ;
2525 expect ( root . toValues ( ) ) . toMatchObject ( {
26- value : 5 , parent : null , left : 1 , right : undefined ,
26+ value : 5 , parent : null , left : 1 , right : null ,
2727 } ) ;
2828 bst . add ( 10 ) ;
2929 expect ( root . toValues ( ) ) . toMatchObject ( {
@@ -50,7 +50,7 @@ describe('Binary Search Tree', () => {
5050 expect ( root . left ) . toBe ( n2 ) ;
5151 expect ( root . right ) . toBe ( n30 ) ;
5252
53- expect ( n30 . left ) . toBe ( undefined ) ;
53+ expect ( n30 . left ) . toBe ( null ) ;
5454 expect ( n30 . right ) . toBe ( n40 ) ;
5555 } ) ;
5656
@@ -68,7 +68,7 @@ describe('Binary Search Tree', () => {
6868 bst . add ( 1 ) ;
6969 expect ( bst . size ) . toBe ( 2 ) ;
7070 expect ( root . toValues ( ) ) . toMatchObject ( {
71- value : 1 , parent : null , left : undefined , right : undefined ,
71+ value : 1 , parent : null , left : null , right : null ,
7272 } ) ;
7373 expect ( root . meta . multiplicity ) . toBe ( 2 ) ;
7474 } ) ;
@@ -78,14 +78,14 @@ describe('Binary Search Tree', () => {
7878 it ( 'should return falsy for empty tree' , ( ) => {
7979 const { found, parent } = bst . findNodeAndParent ( 5 ) ;
8080 expect ( found ) . toBe ( null ) ;
81- expect ( parent ) . toBe ( undefined ) ;
81+ expect ( parent ) . toBe ( null ) ;
8282 } ) ;
8383
8484 it ( 'should return with a single element' , ( ) => {
8585 bst . add ( 5 ) ;
8686 const { found, parent } = bst . findNodeAndParent ( 5 ) ;
8787 expect ( found ) . toMatchObject ( { value : 5 } ) ;
88- expect ( parent ) . toBe ( undefined ) ;
88+ expect ( parent ) . toBe ( null ) ;
8989 } ) ;
9090
9191 it ( 'should return with an element and its parent' , ( ) => {
@@ -100,15 +100,15 @@ describe('Binary Search Tree', () => {
100100 bst . add ( 5 ) ;
101101 bst . add ( 1 ) ;
102102 const { found, parent } = bst . findNodeAndParent ( 10 ) ;
103- expect ( found ) . toBe ( undefined ) ;
103+ expect ( found ) . toBe ( null ) ;
104104 expect ( parent ) . toMatchObject ( { value : 5 } ) ;
105105 } ) ;
106106
107107 it ( 'should find future parent of a node that doesnt exist yet' , ( ) => {
108108 bst . add ( 5 ) ;
109109 bst . add ( 1 ) ;
110110 const { found, parent } = bst . findNodeAndParent ( - 1 ) ;
111- expect ( found ) . toBe ( undefined ) ;
111+ expect ( found ) . toBe ( null ) ;
112112 expect ( parent ) . toMatchObject ( { value : 1 } ) ;
113113 } ) ;
114114 } ) ;
@@ -147,43 +147,43 @@ describe('Binary Search Tree', () => {
147147 } ) ;
148148
149149 it ( 'should NOT find the value 20' , ( ) => {
150- expect ( bst . find ( 20 ) ) . toBe ( undefined ) ;
150+ expect ( bst . find ( 20 ) ) . toBe ( null ) ;
151151 } ) ;
152152 } ) ;
153153
154154 describe ( '#remove' , ( ) => {
155155 it ( 'should remove a left leaf node' , ( ) => {
156156 expect ( n4 . left ) . toBe ( n3 ) ;
157157 bst . remove ( 3 ) ;
158- expect ( n4 . left ) . toBe ( undefined ) ;
158+ expect ( n4 . left ) . toBe ( null ) ;
159159 expect ( bst . size ) . toBe ( 6 ) ;
160160 } ) ;
161161
162162 it ( 'should remove a right leaf node' , ( ) => {
163163 expect ( n30 . right ) . toBe ( n40 ) ;
164164 bst . remove ( 40 ) ;
165- expect ( n30 . right ) . toBe ( undefined ) ;
165+ expect ( n30 . right ) . toBe ( null ) ;
166166 expect ( bst . size ) . toBe ( 6 ) ;
167167 } ) ;
168168
169169 it ( 'should remove a child with one descent on the left' , ( ) => {
170170 expect ( n3 . toValues ( ) ) . toMatchObject ( {
171- value : 3 , left : undefined , right : undefined , parent : 4 ,
171+ value : 3 , left : null , right : null , parent : 4 ,
172172 } ) ;
173173 bst . remove ( 4 ) ;
174174 expect ( n3 . toValues ( ) ) . toMatchObject ( {
175- value : 3 , left : undefined , right : undefined , parent : 5 ,
175+ value : 3 , left : null , right : null , parent : 5 ,
176176 } ) ;
177177 } ) ;
178178
179179 it ( 'should remove a child with one descent on the right' , ( ) => {
180180 bst . remove ( 40 ) ;
181181 expect ( n15 . toValues ( ) ) . toMatchObject ( {
182- value : 15 , left : undefined , right : undefined , parent : 30 ,
182+ value : 15 , left : null , right : null , parent : 30 ,
183183 } ) ;
184184 bst . remove ( 30 ) ;
185185 expect ( n15 . toValues ( ) ) . toMatchObject ( {
186- value : 15 , left : undefined , right : undefined , parent : 10 ,
186+ value : 15 , left : null , right : null , parent : 10 ,
187187 } ) ;
188188 } ) ;
189189
@@ -224,10 +224,10 @@ describe('Binary Search Tree', () => {
224224 expect ( bst . toArray ( ) ) . toEqual ( [
225225 30 ,
226226 15 , 40 ,
227- 5 , undefined , undefined , undefined ,
228- 4 , undefined ,
229- 3 , undefined ,
230- undefined , undefined ] ) ;
227+ 5 , null , null , null ,
228+ 4 , null ,
229+ 3 , null ,
230+ null , null ] ) ;
231231
232232 expect ( bst . size ) . toBe ( 6 ) ;
233233 } ) ;
@@ -312,8 +312,8 @@ describe('Binary Search Tree', () => {
312312
313313 describe ( '#toArray' , ( ) => {
314314 it ( 'should serialize the tree as an array' , ( ) => {
315- expect ( bst . toArray ( ) ) . toEqual ( [ 10 , 5 , 30 , 4 , undefined , 15 , 40 , 3 ,
316- undefined , undefined , undefined , undefined , undefined , undefined , undefined ] ) ;
315+ expect ( bst . toArray ( ) ) . toEqual ( [ 10 , 5 , 30 , 4 , null , 15 , 40 , 3 ,
316+ null , null , null , null , null , null , null ] ) ;
317317 } ) ;
318318 } ) ;
319319
0 commit comments