Skip to content

Commit

Permalink
Merge pull request #738 from olekscode/737-neighbourE-neighbourN-etc-…
Browse files Browse the repository at this point in the history
…dont-work-properly-on-edges

737 neighbour e neighbour n etc dont work properly on edges
  • Loading branch information
olekscode committed Sep 21, 2023
2 parents 671e35b + 4d261ec commit ce43df5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 42 deletions.
6 changes: 6 additions & 0 deletions repository/Cormas-Core/CMSpaceModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ CMSpaceModel >> buildFragmentedEntity: compoundEntity fromCollection: aCollecOfS
^ agg
]

{ #category : #'ESE (regular) - special locations' }
CMSpaceModel >> cellAt: aRowIndex at: aColumnIndex [

^ self elementaryEntities at: (aRowIndex - 1) * column + aColumnIndex
]

{ #category : #accessing }
CMSpaceModel >> cellClass [
"return the SpatialEntityElement class of the current model"
Expand Down
2 changes: 1 addition & 1 deletion repository/Cormas-Core/Cormas.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ Cormas class >> seed [

{ #category : #accessing }
Cormas class >> seed: anInteger [
randomGenerator seed: anInteger
self randomGenerator seed: anInteger
]

{ #category : #'utilities - collection' }
Expand Down
28 changes: 17 additions & 11 deletions repository/Cormas-Mocks/CMMockModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,10 @@ CMMockModel class >> friendlyName [
^ 'MockModel'
]

{ #category : #'initialize-release' }
{ #category : #init }
CMMockModel >> init [

self
createGridLines: numberOfRows
columns: numberOfColumns
neighbourhood: 8
closed: false.
self initEmpty.

self
createN: initialNumberOfCows
Expand All @@ -76,22 +72,32 @@ CMMockModel >> init [
self
createN: initialNumberOfGoats
randomlyLocatedAloneEntities: CMMockGoat.

self initRandom
]

{ #category : #initialization }
{ #category : #init }
CMMockModel >> initAlive [

self theCells do: #initAlive
]

{ #category : #initialization }
{ #category : #init }
CMMockModel >> initDead [
self theCells do: #initDead
]

{ #category : #initialization }
{ #category : #init }
CMMockModel >> initEmpty [

self
createGridLines: numberOfRows
columns: numberOfColumns
neighbourhood: 8
closed: false.

self initRandom
]

{ #category : #init }
CMMockModel >> initRandom [

self theCells do: #initRandom
Expand Down
2 changes: 1 addition & 1 deletion repository/Cormas-Tests/CMProjectManagerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ CMProjectManagerTest >> testModelControlInitMethods [
CMProjectManagerTest >> testModelInitMethods [

self assert: (self projectManager modelInitMethods isKindOf: Array).
self assert: self projectManager modelInitMethods isEmpty.
self assert: self projectManager modelInitMethods size equals: 5.
]

{ #category : #test }
Expand Down
49 changes: 28 additions & 21 deletions repository/Cormas-Tests/CMSpaceModelTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ CMSpaceModelTest >> newTorroidalSpaceModel [
{ #category : #running }
CMSpaceModelTest >> setUp [

super setUp.
spaceModel := CMSpaceModel new
cormasModel: self newTestModel;
yourself.
super setUp.
spaceModel := self newTestModel spaceModel.
]

{ #category : #accessing }
Expand All @@ -58,7 +56,7 @@ CMSpaceModelTest >> testAbsoluteBounds [

| expected|

expected := Rectangle origin: 0 @ 0 extent: 50 @ 50.
expected := Rectangle origin: 0 @ 0 extent: 200 @ 200.
self assert: self spaceModel absoluteBounds equals: expected.
expected := Rectangle origin: 0 @ 0 extent: 30 @ 30.
self spaceModel absoluteBounds: expected.
Expand All @@ -69,15 +67,15 @@ CMSpaceModelTest >> testAbsoluteBounds [
{ #category : #test }
CMSpaceModelTest >> testAbsoluteHeight [

self assert: self spaceModel absoluteHeight equals: 50.
self assert: self spaceModel absoluteHeight equals: 200.


]

{ #category : #test }
CMSpaceModelTest >> testAbsoluteWidth [

self assert: self spaceModel absoluteWidth equals: 50.
self assert: self spaceModel absoluteWidth equals: 200.

]

Expand All @@ -89,23 +87,32 @@ CMSpaceModelTest >> testAllOccupants [
]

{ #category : #test }
CMSpaceModelTest >> testCellsOfLine [

| result |
CMSpaceModelTest >> testCellAtAt [

self spaceModel
nbCount: 4;
dimensions: #(2 2).
result := self spaceModel cellsOfLine: 1.
self assert: (spaceModel cellAt: 1 at: 1) id equals: 1.
self assert: (spaceModel cellAt: 1 at: 4) id equals: 4.

self assert: (spaceModel cellAt: 2 at: 1) id equals: 5.
self assert: (spaceModel cellAt: 2 at: 4) id equals: 8.

self assert: (spaceModel cellAt: 3 at: 1) id equals: 9.
self assert: (spaceModel cellAt: 3 at: 4) id equals: 12.

self assert: (result first isKindOf: CMMockCell).
self assert: (result second isKindOf: CMMockCell).
self assert: (spaceModel cellAt: 4 at: 1) id equals: 13.
self assert: (spaceModel cellAt: 4 at: 4) id equals: 16.
]

self assert: result first id equals: 1.
self assert: result second id equals: 2.
{ #category : #test }
CMSpaceModelTest >> testCellsOfLine [

self assert: result first neighbourhood size equals: 2.
self assert: result second neighbourhood size equals: 3.
| cells |
cells := self spaceModel cellsOfLine: 1.

self assert: cells size equals: 4.

cells withIndexDo: [ :each :i |
self assert: (each isKindOf: CMMockCell).
self assert: each id equals: i ].
]

{ #category : #test }
Expand Down Expand Up @@ -154,7 +161,7 @@ CMSpaceModelTest >> testIsNotTorroidal [
{ #category : #test }
CMSpaceModelTest >> testLine [

self assert: self spaceModel line equals: CMSpaceModel defaultLines.
self assert: self spaceModel line equals: 4.
self spaceModel dimensions: 2 -> 2.
self assert: self spaceModel line equals: 2.

Expand Down
1 change: 1 addition & 0 deletions repository/Cormas-Tests/CMTestObject.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ CMTestObject >> model: anObject [
CMTestObject >> newTestModel [

^ (CMMockModel newWithActiveInit: #init)
randomSeed: 42;
initializeSimulation;
"createGridLines: 20
columns: 10
Expand Down
16 changes: 8 additions & 8 deletions repository/Cormas-UI-Tests/CMR3SpaceTestFixture.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ CMR3SpaceTestFixture >> initialCellStates [
"Initial cell states of a mock model with a fixed random seed"

^ OrderedCollection withAll: #(
dead dead dead dead
dead alive dead dead
dead alive dead alive
dead alive dead dead).
alive alive alive dead
dead dead alive dead
alive dead dead alive
dead dead dead dead).
]

{ #category : #initialization }
Expand Down Expand Up @@ -84,8 +84,8 @@ CMR3SpaceTestFixture >> updatedCellStates [
"Cell states of a mock model with a fixed random seed after one simulation step"

^ OrderedCollection withAll: #(
alive alive alive alive
alive dead alive alive
alive dead alive dead
alive dead alive alive).
dead dead dead alive
alive alive dead alive
dead alive alive dead
alive alive alive alive).
]

0 comments on commit ce43df5

Please sign in to comment.