File tree Expand file tree Collapse file tree
Containers-AVL-Tree-Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -148,6 +148,21 @@ CTAVLTreeTest >> testCopyLargeTree [
148148 self assert: copiedTree asArray equals: tree asArray.
149149]
150150
151+ { #category : ' tests' }
152+ CTAVLTreeTest >> testCopyLeafNode [
153+ | node copiedNode |
154+ node := CTAVLNode new contents: 42 .
155+
156+ copiedNode := node copy.
157+
158+ self assert: copiedNode contents equals: 42 .
159+ self deny: node == copiedNode.
160+
161+ self assert: copiedNode height equals: 1 .
162+ self assert: copiedNode left isNilNode.
163+ self assert: copiedNode right isNilNode
164+ ]
165+
151166{ #category : ' tests' }
152167CTAVLTreeTest >> testCopySingleNode [
153168 | copiedTree |
Original file line number Diff line number Diff line change @@ -60,19 +60,6 @@ CTAVLNode >> contents: anObject [
6060 contents := anObject
6161]
6262
63- { #category : ' copying' }
64- CTAVLNode >> copy [
65- | newNode |
66- newNode := self class new .
67- newNode contents: contents.
68- newNode left: left copy.
69- newNode right: right copy.
70-
71- newNode instVarNamed: ' height' put: height.
72-
73- ^ newNode
74- ]
75-
7663{ #category : ' enumerating' }
7764CTAVLNode >> elementsFrom: min to: max into: aCollection [
7865
@@ -186,6 +173,14 @@ CTAVLNode >> left: aNode [
186173 aNode ifNotNil: [ aNode parent: self ]
187174]
188175
176+ { #category : ' copying' }
177+ CTAVLNode >> postCopy [
178+ super postCopy.
179+
180+ left isNilNode ifFalse: [ left := left copy ].
181+ right isNilNode ifFalse: [ right := right copy ]
182+ ]
183+
189184{ #category : ' enumerating' }
190185CTAVLNode >> postOrderDo: aBlock [
191186
You can’t perform that action at this time.
0 commit comments