Skip to content

Commit cdad99e

Browse files
committed
Merge 40c05ae
2 parents 115bf2c + 40c05ae commit cdad99e

File tree

2 files changed

+157
-25
lines changed

2 files changed

+157
-25
lines changed

src/Containers-Array2D-Tests/CTArray2DTest.class.st

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,25 @@ CTArray2DTest >> testCannotAccessWithWrongCoordinates [
164164
self should: [ self arrayClass width2Height3 atColumn: 6 atRow: 1 ] raise: SubscriptOutOfBounds
165165
]
166166

167+
{ #category : 'tests' }
168+
CTArray2DTest >> testColumns [
169+
| foo |
170+
foo := self arrayClass width2Height3.
171+
self assert: foo columns equals: #(#(1 3 5) #(2 4 6))
172+
]
173+
174+
{ #category : 'tests' }
175+
CTArray2DTest >> testColumnsDo [
176+
| foo array columnIndex |
177+
foo := self arrayClass width2Height3.
178+
array := Array new: 2.
179+
columnIndex := 1.
180+
foo columnsDo: [ :column |
181+
array at: columnIndex put: column.
182+
columnIndex := columnIndex + 1 ].
183+
self assert: array equals: #(#(1 3 5) #(2 4 6))
184+
]
185+
167186
{ #category : 'tests-copying' }
168187
CTArray2DTest >> testCopy [
169188
| foo cop |
@@ -239,6 +258,78 @@ CTArray2DTest >> testFromArray [
239258

240259
]
241260

261+
{ #category : 'tests-enumeration' }
262+
CTArray2DTest >> testFromBottomToTopFromLeftToRightDo [
263+
|foo res|
264+
foo := self arrayClass width2Height3.
265+
res := OrderedCollection new.
266+
foo fromBottomToTopFromLeftToRightDo: [ :each | res add: each ].
267+
self assert: res equals: #(5 3 1 6 4 2) asOrderedCollection
268+
]
269+
270+
{ #category : 'tests-enumeration' }
271+
CTArray2DTest >> testFromBottomToTopFromRightToLeftDo [
272+
|foo res|
273+
foo := self arrayClass width2Height3.
274+
res := OrderedCollection new.
275+
foo fromBottomToTopFromRightToLeftDo: [ :each | res add: each ].
276+
self assert: res equals: #(6 4 2 5 3 1) asOrderedCollection
277+
]
278+
279+
{ #category : 'tests-enumeration' }
280+
CTArray2DTest >> testFromLeftToRightFromBottomToTopDo [
281+
|foo res|
282+
foo := self arrayClass width2Height3.
283+
res := OrderedCollection new.
284+
foo fromLeftToRightFromBottomToTopDo: [ :each | res add: each ].
285+
self assert: res equals: #(5 6 3 4 1 2) asOrderedCollection
286+
]
287+
288+
{ #category : 'tests-enumeration' }
289+
CTArray2DTest >> testFromLeftToRightFromTopToBottomDo [
290+
|foo res|
291+
foo := self arrayClass width2Height3.
292+
res := OrderedCollection new.
293+
foo fromLeftToRightFromTopToBottomDo: [ :each | res add: each ].
294+
self assert: res equals: #(1 2 3 4 5 6) asOrderedCollection
295+
]
296+
297+
{ #category : 'tests-enumeration' }
298+
CTArray2DTest >> testFromRightToLeftFromBottomToTopDo [
299+
|foo res|
300+
foo := self arrayClass width2Height3.
301+
res := OrderedCollection new.
302+
foo fromRightToLeftFromBottomToTopDo: [ :each | res add: each ].
303+
self assert: res equals: #(6 5 4 3 2 1) asOrderedCollection
304+
]
305+
306+
{ #category : 'tests-enumeration' }
307+
CTArray2DTest >> testFromRightToLeftFromTopToBottomDo [
308+
|foo res|
309+
foo := self arrayClass width2Height3.
310+
res := OrderedCollection new.
311+
foo fromRightToLeftFromTopToBottomDo: [ :each | res add: each ].
312+
self assert: res equals: #(2 1 4 3 6 5) asOrderedCollection
313+
]
314+
315+
{ #category : 'tests-enumeration' }
316+
CTArray2DTest >> testFromTopToBottomFromLeftToRightDo [
317+
|foo res|
318+
foo := self arrayClass width2Height3.
319+
res := OrderedCollection new.
320+
foo fromTopToBottomFromLeftToRightDo: [ :each | res add: each ].
321+
self assert: res equals: #(1 3 5 2 4 6) asOrderedCollection
322+
]
323+
324+
{ #category : 'tests-enumeration' }
325+
CTArray2DTest >> testFromTopToBottomFromRightToLeftDo [
326+
|foo res|
327+
foo := self arrayClass width2Height3.
328+
res := OrderedCollection new.
329+
foo fromTopToBottomFromRightToLeftDo: [ :each | res add: each ].
330+
self assert: res equals: #(2 4 6 1 3 5) asOrderedCollection
331+
]
332+
242333
{ #category : 'tests-accessing' }
243334
CTArray2DTest >> testHeight [
244335

@@ -253,17 +344,6 @@ CTArray2DTest >> testIndexXY [
253344
self assert: (foo indexX: 2 y: 3) equals: (3-1)*(foo width)+2
254345
]
255346

256-
{ #category : 'tests' }
257-
CTArray2DTest >> testLeftToRightFromBottomToTopDo [
258-
259-
| a2d res |
260-
a2d := CTArray2D fromArray: #(1 2 3 4 5 6) width: 3.
261-
res := OrderedCollection new.
262-
a2d leftToRightFromBottomToTopDo: [ :each | res add: each ].
263-
self assert: res equals: #(4 5 6 1 2 3 ) asOrderedCollection
264-
265-
]
266-
267347
{ #category : 'tests-accessing' }
268348
CTArray2DTest >> testNeighborsAtColumnAtRow [
269349

src/Containers-Array2D/CTArray2D.class.st

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ CTArray2D >> atX: x atY: y put: value [
245245
^ contents at: (self indexX: x y: y) put: value
246246
]
247247

248+
{ #category : 'converting' }
249+
CTArray2D >> columns [
250+
^ (1 to: self width) collect: [ :columnIndex | self atColumn: columnIndex ]
251+
]
252+
253+
{ #category : 'enumeration' }
254+
CTArray2D >> columnsDo: aBlock [
255+
1 to: self width do: [ :i | aBlock value: (self atColumn: i) ]
256+
]
257+
248258
{ #category : 'private' }
249259
CTArray2D >> contents [
250260

@@ -275,6 +285,62 @@ CTArray2D >> extent: extent fromArray: anArray [
275285
contents := anArray
276286
]
277287

288+
{ #category : 'enumerating' }
289+
CTArray2D >> fromBottomToTopFromLeftToRightDo: aBlock [
290+
1 to: self width do: [:col |
291+
self height to: 1 by: -1 do: [:row |
292+
aBlock value: (self atColumn: col atRow: row)]]
293+
]
294+
295+
{ #category : 'enumerating' }
296+
CTArray2D >> fromBottomToTopFromRightToLeftDo: aBlock [
297+
self width to: 1 by: -1 do: [:col |
298+
self height to: 1 by: -1 do: [:row |
299+
aBlock value: (self atColumn: col atRow: row)]]
300+
]
301+
302+
{ #category : 'enumerating' }
303+
CTArray2D >> fromLeftToRightFromBottomToTopDo: aBlock [
304+
self height to: 1 by: -1 do: [:row |
305+
1 to: self width do: [:col |
306+
aBlock value: (self atColumn: col atRow: row)]]
307+
]
308+
309+
{ #category : 'enumerating' }
310+
CTArray2D >> fromLeftToRightFromTopToBottomDo: aBlock [
311+
1 to: self height do: [ :row |
312+
1 to: self width do: [ :col |
313+
aBlock value: (self atColumn: col atRow: row) ] ]
314+
]
315+
316+
{ #category : 'enumerating' }
317+
CTArray2D >> fromRightToLeftFromBottomToTopDo: aBlock [
318+
self height to: 1 by: -1 do: [:row |
319+
self width to: 1 by: -1 do: [:col |
320+
aBlock value: (self atColumn: col atRow: row)]]
321+
]
322+
323+
{ #category : 'enumerating' }
324+
CTArray2D >> fromRightToLeftFromTopToBottomDo: aBlock [
325+
1 to: self height do: [:row |
326+
self width to: 1 by: -1 do: [:col |
327+
aBlock value: (self atColumn: col atRow: row)]]
328+
]
329+
330+
{ #category : 'enumerating' }
331+
CTArray2D >> fromTopToBottomFromLeftToRightDo: aBlock [
332+
1 to: self width do: [:col |
333+
1 to: self height do: [:row |
334+
aBlock value: (self atColumn: col atRow: row)]]
335+
]
336+
337+
{ #category : 'enumerating' }
338+
CTArray2D >> fromTopToBottomFromRightToLeftDo: aBlock [
339+
self width to: 1 by: -1 do: [:col |
340+
1 to: self height do: [:row |
341+
aBlock value: (self atColumn: col atRow: row)]]
342+
]
343+
278344
{ #category : 'comparing' }
279345
CTArray2D >> hash [
280346

@@ -307,20 +373,6 @@ CTArray2D >> isSelfEvaluating [
307373
^ self class == CTArray2D and: [ contents isSelfEvaluating ]
308374
]
309375

310-
{ #category : 'enumerating' }
311-
CTArray2D >> leftToRightFromBottomToTopDo: aBlock [
312-
"Apply a block to each element following that order left to right but from bottom to top"
313-
"123
314-
456
315-
=>
316-
456123
317-
"
318-
319-
self height to: 1 by: -1 do: [:row |
320-
1 to: self width do: [:col |
321-
aBlock value: (self atColumn: col atRow: row)]]
322-
]
323-
324376
{ #category : 'enumerating' }
325377
CTArray2D >> neighborsAtColumn: col atRow: row [
326378

0 commit comments

Comments
 (0)