Skip to content

Commit e0c1ee0

Browse files
committed
Fixed inspector presenter
1 parent 04663dc commit e0c1ee0

File tree

7 files changed

+72
-8
lines changed

7 files changed

+72
-8
lines changed

src/BaselineOfContainersAVLTree/BaselineOfContainersAVLTree.class.st

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ BaselineOfContainersAVLTree >> baseline: spec [
2323

2424
"Groups"
2525
spec
26-
group: 'Core'
27-
with: #( 'Containers-AVL-Tree' 'Containers-AVL-Tree-Inspector' );
26+
group: 'Core' with: #( 'Containers-AVL-Tree' 'Containers-AVL-Tree-Inspector' );
2827
group: 'Tests' with: #( 'Containers-AVL-Tree-Tests' ).
2928

3029
spec group: 'default' with: #( 'Core' 'Tests' ) ]
31-
]
30+
]
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
Extension { #name : 'CTAVLTree' }
22

33
{ #category : '*Containers-AVL-Tree-Inspector' }
4-
CTAVLTree >> inspectorCanvas [
4+
CTAVLTree >> inspectorCanvas: aBuilder [
5+
56
<inspectorPresentationOrder: 90 title: 'AVL'>
6-
^ CTAVLTreeVisualizer new
7-
tree: self;
8-
asPresenter
7+
^ (aBuilder instantiate: SpRoassalInspectorPresenter)
8+
canvas: (CTAVLTreeVisualizer new
9+
tree: self;
10+
build;
11+
canvas);
12+
yourself
913
]

src/Containers-AVL-Tree-Tests/CTAVLTreeTest.class.st

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ CTAVLTreeTest >> testAddSingleElement [
3838
self assert: tree height equals: 1
3939
]
4040

41+
{ #category : 'tests' }
42+
CTAVLTreeTest >> testAllChildren [
43+
44+
| elements |
45+
elements := (1 to: 10000) collect: [ :i | Random new nextIntegerBetween: 1 and: 100000000 ].
46+
tree addAll: elements.
47+
48+
self assertCollection: (tree allChildren collect: #contents) hasSameElements: elements
49+
]
50+
4151
{ #category : 'tests' }
4252
CTAVLTreeTest >> testAnySatisfy [
4353

src/Containers-AVL-Tree/CTAVLAbstractNode.class.st

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ CTAVLAbstractNode >> balanceFactor [
2828
^ self subclassResponsibility
2929
]
3030

31+
{ #category : 'accessing' }
32+
CTAVLAbstractNode >> children [
33+
34+
^ { }
35+
]
36+
3137
{ #category : 'accessing' }
3238
CTAVLAbstractNode >> contents [
3339

@@ -95,6 +101,12 @@ CTAVLAbstractNode >> inOrderDo: aBlock [
95101
^ self subclassResponsibility
96102
]
97103

104+
{ #category : 'testing' }
105+
CTAVLAbstractNode >> isBalanced [
106+
107+
^ false
108+
]
109+
98110
{ #category : 'testing' }
99111
CTAVLAbstractNode >> isEmpty [
100112

@@ -107,6 +119,12 @@ CTAVLAbstractNode >> isLeaf [
107119
^ self subclassResponsibility
108120
]
109121

122+
{ #category : 'testing' }
123+
CTAVLAbstractNode >> isNilNode [
124+
125+
^ false
126+
]
127+
110128
{ #category : 'accessing' }
111129
CTAVLAbstractNode >> parent [
112130

src/Containers-AVL-Tree/CTAVLNilNode.class.st

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ CTAVLNilNode >> isLeaf [
102102
^ false
103103
]
104104

105+
{ #category : 'testing' }
106+
CTAVLNilNode >> isNilNode [
107+
108+
^ true
109+
]
110+
105111
{ #category : 'enumerating' }
106112
CTAVLNilNode >> postOrderDo: aBlock [
107113

src/Containers-AVL-Tree/CTAVLNode.class.st

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ CTAVLNode >> balanceFactor [
4242
^ left height - right height
4343
]
4444

45+
{ #category : 'accessing' }
46+
CTAVLNode >> children [
47+
48+
^ { left . right }
49+
]
50+
4551
{ #category : 'accessing' }
4652
CTAVLNode >> contents [
4753

@@ -137,6 +143,12 @@ CTAVLNode >> initialize [
137143
height := 1
138144
]
139145

146+
{ #category : 'testing' }
147+
CTAVLNode >> isBalanced [
148+
149+
^ (left height - right height) abs <= 1
150+
]
151+
140152
{ #category : 'testing' }
141153
CTAVLNode >> isEmpty [
142154

@@ -298,7 +310,7 @@ CTAVLNode >> successorOf: anObject [
298310
{ #category : 'private' }
299311
CTAVLNode >> updateHeight [
300312

301-
height := 1 + (left height max: right height)
313+
height := 1 + (left height max: right height)
302314
]
303315

304316
{ #category : 'private' }

src/Containers-AVL-Tree/CTAVLTree.class.st

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ CTAVLTree >> addAll: aCollection [
3636
^ aCollection
3737
]
3838

39+
{ #category : 'accessing' }
40+
CTAVLTree >> allChildren [
41+
42+
| currentNode nodesToVisit children |
43+
children := Set new.
44+
nodesToVisit := LinkedList with: root.
45+
46+
[ nodesToVisit isNotEmpty ] whileTrue: [
47+
currentNode := nodesToVisit removeFirst.
48+
children add: currentNode.
49+
nodesToVisit addAll: (currentNode children reject: #isNilNode) ].
50+
51+
^ children
52+
]
53+
3954
{ #category : 'enumerating' }
4055
CTAVLTree >> anySatisfy: aBlock [
4156

0 commit comments

Comments
 (0)