File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,14 @@ function delete! end
8787# IO METHODS
8888# -----------
8989
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 )
9198 name = nameof (typeof (tree))
9299 if isnothing (tree. root)
93100 print (io, " $name ()" )
119126AbstractTrees. NodeType (:: Type{<:BinaryNode} ) = AbstractTrees. HasNodeType ()
120127AbstractTrees. nodetype (T:: Type{<:BinaryNode} ) = T
121128
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 )
123136 ioctx = IOContext (io, :compact => true , :limit => true )
124137 val = value (node)
125138 if isnothing (val)
Original file line number Diff line number Diff line change @@ -216,28 +216,34 @@ const BT = BinaryTrees
216216
217217 # show
218218 tree = AVLTree {Int,Int} ()
219- @test sprint (show, MIME ( " text/plain " ), tree) == " AVLTree()"
219+ @test sprint (show, tree) == " AVLTree()"
220220 BT. insert! (tree, 3 , 30 )
221221 BT. insert! (tree, 2 , 20 )
222222 BT. insert! (tree, 4 , 40 )
223223 BT. insert! (tree, 1 , 10 )
224224 BT. insert! (tree, 5 , 50 )
225- @test sprint (show, MIME ( " text/plain " ), tree) == """
225+ @test sprint (show, tree) == """
226226 AVLTree
227227 3 => 30
228228 ├─ 2 => 20
229229 │ └─ 1 => 10
230230 └─ 4 => 40
231231 └─ 5 => 50"""
232232
233+ node = BT. search (tree, 1 )
234+ @test sprint (show, node) == " AVLNode(1 => 10)"
235+
233236 tree = AVLTree {Int} ()
234237 BT. insert! (tree, 2 )
235238 BT. insert! (tree, 1 )
236239 BT. insert! (tree, 3 )
237- @test sprint (show, MIME ( " text/plain " ), tree) == """
240+ @test sprint (show, tree) == """
238241 AVLTree
239242 2
240243 ├─ 1
241244 └─ 3"""
245+
246+ node = BT. search (tree, 1 )
247+ @test sprint (show, node) == " AVLNode(1)"
242248 end
243249end
You can’t perform that action at this time.
0 commit comments