1
+ # frozen_string_literal: true
2
+
1
3
class BinarySearchTree
2
4
class Node
3
5
attr_accessor :left , :right , :value
@@ -152,8 +154,8 @@ def find_leftmost(node)
152
154
bst . insert ( 1 )
153
155
end
154
156
155
- describe ' #insert' do
156
- it ' adds a value to the tree' do
157
+ describe " #insert" do
158
+ it " adds a value to the tree" do
157
159
expect ( bst . traverse ) . to eq ( { value : 9 ,
158
160
left : { value : 4 ,
159
161
left : { value : 1 , left : nil , right : nil } ,
@@ -163,20 +165,20 @@ def find_leftmost(node)
163
165
end
164
166
end
165
167
166
- describe ' #lookup' do
167
- it ' finds a value in the tree' do
168
+ describe " #lookup" do
169
+ it " finds a value in the tree" do
168
170
node = bst . lookup ( 15 )
169
171
expect ( node . value ) . to eq ( 15 )
170
172
end
171
173
172
- it ' returns nil for a value not in the tree' do
174
+ it " returns nil for a value not in the tree" do
173
175
node = bst . lookup ( 100 )
174
176
expect ( node ) . to be_nil
175
177
end
176
178
end
177
179
178
- describe ' #remove' do
179
- it ' removes a leaf node' do
180
+ describe " #remove" do
181
+ it " removes a leaf node" do
180
182
expect ( bst . remove ( 1 ) ) . to be true
181
183
182
184
expect ( bst . traverse ) . to eq ( { value : 9 ,
@@ -186,7 +188,7 @@ def find_leftmost(node)
186
188
right : { value : 170 , left : nil , right : nil } } } )
187
189
end
188
190
189
- it ' removes a node with one child' do
191
+ it " removes a node with one child" do
190
192
expect ( bst . remove ( 20 ) ) . to be true
191
193
192
194
expect ( bst . traverse ) . to eq ( { value : 9 ,
@@ -196,7 +198,7 @@ def find_leftmost(node)
196
198
right : nil } } )
197
199
end
198
200
199
- it ' removes a node with two children' do
201
+ it " removes a node with two children" do
200
202
expect ( bst . remove ( 4 ) ) . to be true
201
203
202
204
expect ( bst . traverse ) . to eq ( { value : 9 ,
@@ -206,7 +208,7 @@ def find_leftmost(node)
206
208
right : { value : 170 , left : nil , right : nil } } } )
207
209
end
208
210
209
- it ' returns false for a value not in the tree' do
211
+ it " returns false for a value not in the tree" do
210
212
expect ( bst . remove ( 100 ) ) . to be false
211
213
end
212
214
end
0 commit comments