@@ -88,76 +88,76 @@ describe('Binary Search Tree', function () {
88
88
89
89
90
90
it ( 'should remove a leaf without altering anything else in ' +
91
- 'the structure of the tree' , function ( ) {
91
+ 'the structure of the tree' , function ( ) {
92
92
93
- bst . remove ( 0 ) ;
94
- /**
95
- * 4
96
- * 2 8
97
- * 1 3 5 10
98
- * 2.5 100
99
- */
100
- var a = [ ] ;
101
- bfs ( bst . root , callbackGenerator ( a ) ) ;
102
- assert . deepEqual ( a , [ 4 , 2 , 8 , 1 , 3 , 5 , 10 , 2.5 , 100 ] ) ;
103
- } ) ;
93
+ bst . remove ( 0 ) ;
94
+ /**
95
+ * 4
96
+ * 2 8
97
+ * 1 3 5 10
98
+ * 2.5 100
99
+ */
100
+ var a = [ ] ;
101
+ bfs ( bst . root , callbackGenerator ( a ) ) ;
102
+ assert . deepEqual ( a , [ 4 , 2 , 8 , 1 , 3 , 5 , 10 , 2.5 , 100 ] ) ;
103
+ } ) ;
104
104
105
105
it ( 'should remove an element with just one child and substitute ' +
106
- 'it as the root of only subtree' , function ( ) {
106
+ 'it as the root of only subtree' , function ( ) {
107
107
108
- bst . remove ( 10 ) ;
109
- /**
110
- * 4
111
- * 2 8
112
- * 1 3 5 100
113
- * 2.5
114
- */
115
- var a = [ ] ;
116
- bfs ( bst . root , callbackGenerator ( a ) ) ;
117
- assert . deepEqual ( a , [ 4 , 2 , 8 , 1 , 3 , 5 , 100 , 2.5 ] ) ;
118
- } ) ;
108
+ bst . remove ( 10 ) ;
109
+ /**
110
+ * 4
111
+ * 2 8
112
+ * 1 3 5 100
113
+ * 2.5
114
+ */
115
+ var a = [ ] ;
116
+ bfs ( bst . root , callbackGenerator ( a ) ) ;
117
+ assert . deepEqual ( a , [ 4 , 2 , 8 , 1 , 3 , 5 , 100 , 2.5 ] ) ;
118
+ } ) ;
119
119
120
120
it ( 'should substitute an element by the leftmost child in the right ' +
121
- 'subtree and remove it as a leaf' , function ( ) {
122
- /**
123
- * 4
124
- * 2 8
125
- * 1 3 5 100
126
- * 2.5
127
- */
128
- bst . remove ( 2 ) ;
129
- /**
130
- * 4
131
- * 2.5 8
132
- * 1 3 5 100
133
- *
134
- */
135
- var a = [ ] ;
136
- bfs ( bst . root , callbackGenerator ( a ) ) ;
137
- assert . deepEqual ( a , [ 4 , 2.5 , 8 , 1 , 3 , 5 , 100 ] ) ;
121
+ 'subtree and remove it as a leaf' , function ( ) {
122
+ /**
123
+ * 4
124
+ * 2 8
125
+ * 1 3 5 100
126
+ * 2.5
127
+ */
128
+ bst . remove ( 2 ) ;
129
+ /**
130
+ * 4
131
+ * 2.5 8
132
+ * 1 3 5 100
133
+ *
134
+ */
135
+ var a = [ ] ;
136
+ bfs ( bst . root , callbackGenerator ( a ) ) ;
137
+ assert . deepEqual ( a , [ 4 , 2.5 , 8 , 1 , 3 , 5 , 100 ] ) ;
138
138
139
- bst . remove ( 4 ) ;
140
- /**
141
- * 5
142
- * 2.5 8
143
- * 1 3 100
144
- *
145
- */
146
- a = [ ] ;
147
- bfs ( bst . root , callbackGenerator ( a ) ) ;
148
- assert . deepEqual ( a , [ 5 , 2.5 , 8 , 1 , 3 , 100 ] ) ;
139
+ bst . remove ( 4 ) ;
140
+ /**
141
+ * 5
142
+ * 2.5 8
143
+ * 1 3 100
144
+ *
145
+ */
146
+ a = [ ] ;
147
+ bfs ( bst . root , callbackGenerator ( a ) ) ;
148
+ assert . deepEqual ( a , [ 5 , 2.5 , 8 , 1 , 3 , 100 ] ) ;
149
149
150
- bst . remove ( 2.5 ) ;
151
- /**
152
- * 5
153
- * 3 8
154
- * 1 100
155
- *
156
- */
157
- a = [ ] ;
158
- bfs ( bst . root , callbackGenerator ( a ) ) ;
159
- assert . deepEqual ( a , [ 5 , 3 , 8 , 1 , 100 ] ) ;
160
- } ) ;
150
+ bst . remove ( 2.5 ) ;
151
+ /**
152
+ * 5
153
+ * 3 8
154
+ * 1 100
155
+ *
156
+ */
157
+ a = [ ] ;
158
+ bfs ( bst . root , callbackGenerator ( a ) ) ;
159
+ assert . deepEqual ( a , [ 5 , 3 , 8 , 1 , 100 ] ) ;
160
+ } ) ;
161
161
162
162
it ( 'should always return the right root and size' , function ( ) {
163
163
var bst = new BST ( ) ;
@@ -194,14 +194,15 @@ describe('Binary Search Tree with custom comparator', function () {
194
194
return a . length < b . length ? - 1 : 1 ;
195
195
} ;
196
196
197
- it ( 'should insert elements respecting the BST restrictions' , function ( ) {
198
- var bst = new BST ( strLenCompare ) ;
199
- bst . insert ( 'banana' ) ;
200
- bst . insert ( 'apple' ) ;
201
- bst . insert ( 'pineapple' ) ;
202
- bst . insert ( 'watermelon' ) ;
203
- assert . equal ( bst . size , 4 ) ;
204
- } ) ;
197
+ it (
198
+ 'should insert elements respecting the BST restrictions' , function ( ) {
199
+ var bst = new BST ( strLenCompare ) ;
200
+ bst . insert ( 'banana' ) ;
201
+ bst . insert ( 'apple' ) ;
202
+ bst . insert ( 'pineapple' ) ;
203
+ bst . insert ( 'watermelon' ) ;
204
+ assert . equal ( bst . size , 4 ) ;
205
+ } ) ;
205
206
206
207
it ( 'should check if an element exists (in O(lg n))' , function ( ) {
207
208
var bst = new BST ( strLenCompare ) ;
@@ -245,42 +246,42 @@ describe('Binary Search Tree with custom comparator', function () {
245
246
} ) ;
246
247
247
248
it ( 'should remove a leaf without altering anything else in ' +
248
- 'the structure of the tree' , function ( ) {
249
+ 'the structure of the tree' , function ( ) {
249
250
250
- bst . remove ( 'watermelon' ) ;
251
- /**
252
- * 'banana'
253
- * 'apple' 'pineapple'
254
- * 'pear'
255
- */
256
- var a = [ ] ;
257
- bfs ( bst . root , callbackGenerator ( a ) ) ;
258
- assert . deepEqual ( a , [ 'banana' , 'apple' , 'pineapple' , 'pear' ] ) ;
259
- } ) ;
251
+ bst . remove ( 'watermelon' ) ;
252
+ /**
253
+ * 'banana'
254
+ * 'apple' 'pineapple'
255
+ * 'pear'
256
+ */
257
+ var a = [ ] ;
258
+ bfs ( bst . root , callbackGenerator ( a ) ) ;
259
+ assert . deepEqual ( a , [ 'banana' , 'apple' , 'pineapple' , 'pear' ] ) ;
260
+ } ) ;
260
261
261
262
it ( 'should remove an element with just one child and substitute ' +
262
- 'it as the root of only subtree' , function ( ) {
263
+ 'it as the root of only subtree' , function ( ) {
263
264
264
- bst . remove ( 'apple' ) ;
265
- /**
266
- * 'banana'
267
- * 'pear' 'pineapple'
268
- */
269
- var a = [ ] ;
270
- bfs ( bst . root , callbackGenerator ( a ) ) ;
271
- assert . deepEqual ( a , [ 'banana' , 'pear' , 'pineapple' ] ) ;
272
- } ) ;
265
+ bst . remove ( 'apple' ) ;
266
+ /**
267
+ * 'banana'
268
+ * 'pear' 'pineapple'
269
+ */
270
+ var a = [ ] ;
271
+ bfs ( bst . root , callbackGenerator ( a ) ) ;
272
+ assert . deepEqual ( a , [ 'banana' , 'pear' , 'pineapple' ] ) ;
273
+ } ) ;
273
274
274
275
it ( 'should substitute an element by the leftmost child in the right ' +
275
- 'subtree and remove it as a leaf' , function ( ) {
276
+ 'subtree and remove it as a leaf' , function ( ) {
276
277
277
- bst . remove ( 'banana' ) ;
278
- /**
279
- * 'pineapple'
280
- * 'pear'
281
- */
282
- var a = [ ] ;
283
- bfs ( bst . root , callbackGenerator ( a ) ) ;
284
- assert . deepEqual ( a , [ 'pineapple' , 'pear' ] ) ;
285
- } ) ;
278
+ bst . remove ( 'banana' ) ;
279
+ /**
280
+ * 'pineapple'
281
+ * 'pear'
282
+ */
283
+ var a = [ ] ;
284
+ bfs ( bst . root , callbackGenerator ( a ) ) ;
285
+ assert . deepEqual ( a , [ 'pineapple' , 'pear' ] ) ;
286
+ } ) ;
286
287
} ) ;
0 commit comments