File tree 2 files changed +24
-5
lines changed
2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,14 @@ function delete! end
87
87
# IO METHODS
88
88
# -----------
89
89
90
- function Base. show (io:: IO , :: MIME"text/plain" , tree:: BinaryTree )
90
+ function Base. show (io:: IO , node:: BinaryNode )
91
+ name = nameof (typeof (node))
92
+ print (io, " $name (" )
93
+ _printkeyvalue (io, node)
94
+ print (io, " )" )
95
+ end
96
+
97
+ function Base. show (io:: IO , tree:: BinaryTree )
91
98
name = nameof (typeof (tree))
92
99
if isnothing (tree. root)
93
100
print (io, " $name ()" )
119
126
AbstractTrees. NodeType (:: Type{<:BinaryNode} ) = AbstractTrees. HasNodeType ()
120
127
AbstractTrees. nodetype (T:: Type{<:BinaryNode} ) = T
121
128
122
- function AbstractTrees. printnode (io:: IO , node:: BinaryNode )
129
+ AbstractTrees. printnode (io:: IO , node:: BinaryNode ) = _printkeyvalue (io, node)
130
+
131
+ # -----------------
132
+ # HELPER FUNCTIONS
133
+ # -----------------
134
+
135
+ function _printkeyvalue (io:: IO , node:: BinaryNode )
123
136
ioctx = IOContext (io, :compact => true , :limit => true )
124
137
val = value (node)
125
138
if isnothing (val)
Original file line number Diff line number Diff line change @@ -216,28 +216,34 @@ const BT = BinaryTrees
216
216
217
217
# show
218
218
tree = AVLTree {Int,Int} ()
219
- @test sprint (show, MIME ( " text/plain " ), tree) == " AVLTree()"
219
+ @test sprint (show, tree) == " AVLTree()"
220
220
BT. insert! (tree, 3 , 30 )
221
221
BT. insert! (tree, 2 , 20 )
222
222
BT. insert! (tree, 4 , 40 )
223
223
BT. insert! (tree, 1 , 10 )
224
224
BT. insert! (tree, 5 , 50 )
225
- @test sprint (show, MIME ( " text/plain " ), tree) == """
225
+ @test sprint (show, tree) == """
226
226
AVLTree
227
227
3 => 30
228
228
├─ 2 => 20
229
229
│ └─ 1 => 10
230
230
└─ 4 => 40
231
231
└─ 5 => 50"""
232
232
233
+ node = BT. search (tree, 1 )
234
+ @test sprint (show, node) == " AVLNode(1 => 10)"
235
+
233
236
tree = AVLTree {Int} ()
234
237
BT. insert! (tree, 2 )
235
238
BT. insert! (tree, 1 )
236
239
BT. insert! (tree, 3 )
237
- @test sprint (show, MIME ( " text/plain " ), tree) == """
240
+ @test sprint (show, tree) == """
238
241
AVLTree
239
242
2
240
243
├─ 1
241
244
└─ 3"""
245
+
246
+ node = BT. search (tree, 1 )
247
+ @test sprint (show, node) == " AVLNode(1)"
242
248
end
243
249
end
You can’t perform that action at this time.
0 commit comments