Skip to content

Commit

Permalink
refactored tests + CAGame
Browse files Browse the repository at this point in the history
  • Loading branch information
kpawlak committed Jul 12, 2024
1 parent 425aa61 commit a5a61f8
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 214 deletions.
10 changes: 5 additions & 5 deletions src/ComputationalArt/CACellMorph.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ CACellMorph >> handlesMouseOver: anEvent [

{
#category : #handling,
#'squeak_changestamp' : 'KoPa 7/12/2024 18:38'
#'squeak_changestamp' : 'KoPa 7/12/2024 20:29'
}
CACellMorph >> mouseDown: anEvent [

anEvent redButtonPressed
ifTrue: [game putCellAtRow: row andCol: col]
ifFalse: [game toggleBrushActive].
ifTrue: [game putCellAtRow: row andCol: col.]
ifFalse: [game toggleBrushActive.].
]

{
#category : #handling,
#'squeak_changestamp' : 'KoPa 7/12/2024 18:39'
#'squeak_changestamp' : 'KoPa 7/12/2024 20:29'
}
CACellMorph >> mouseEnter: anEvent [

game brushActive
ifTrue: [game putCellAtRow: row andCol: col].
ifTrue: [game putCellAtRow: row andCol: col.].

]

Expand Down
42 changes: 21 additions & 21 deletions src/ComputationalArt/CADisplay.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ CADisplay >> initialize [

{
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 18:58'
#'squeak_changestamp' : 'KoPa 7/12/2024 20:30'
}
CADisplay >> showGrid: aGrid [

Expand All @@ -130,8 +130,8 @@ CADisplay >> showGrid: aGrid [

self wipeCells.

1 to: rows do: [ :rowIndex |
1 to: cols do: [ :colIndex |
1 to: rows do: [:rowIndex |
1 to: cols do: [:colIndex |
cell := aGrid getCellAtRow: rowIndex andCol: colIndex.
cellMorph := Morph new
extent: size @ size;
Expand All @@ -140,12 +140,12 @@ CADisplay >> showGrid: aGrid [
borderWidth: border;
position: (((colIndex-1) * (size+gap)) @ ((rowIndex-1) * (size+gap)) + origin).
viewMorph addMorph: cellMorph.
cells add: cellMorph. ]].
cells add: cellMorph.]].
]

{
#category : #functional,
#'squeak_changestamp' : 'KoPa 7/12/2024 18:58'
#'squeak_changestamp' : 'KoPa 7/12/2024 20:31'
}
CADisplay >> step [

Expand All @@ -163,29 +163,29 @@ CADisplay >> step [
cells isEmpty
ifTrue: [
(1 to: rows)
do: [ :rowIndex | (1 to: cols)
do: [ :colIndex |
do: [:rowIndex |
(1 to: cols)
do: [:colIndex |
cell := aGrid getCellAtRow: rowIndex andCol: colIndex.
cellMorph := CACellMorph new extent: size @ size;
borderColor: Color gray;

color: (blockLookup colorAt: cell);
color: (blockLookup colorAt: cell);
borderWidth: border;
position: colIndex - 1 * (size + gap) @ (rowIndex - 1 * (size + gap)) + origin;
row: rowIndex;
col: colIndex;
game: attachedGame.
row: rowIndex;
col: colIndex;
game: attachedGame.
viewMorph addMorph: cellMorph.
cells add: cellMorph. ]]].
cells add: cellMorph.]]].
cells isEmpty
ifFalse: [
(1 to: rows)
do: [ :rowIndex | (1 to: cols)
do: [ :colIndex |
ifFalse: [(1 to: rows)
do: [:rowIndex |
(1 to: cols)
do: [:colIndex |
cell := aGrid getCellAtRow: rowIndex andCol: colIndex.
cellMorph := cells at: rowIndex - 1 * rows + colIndex.
cellMorph
color: (blockLookup colorAt: cell). ]]].
color: (blockLookup colorAt: cell).]]].
]

{
Expand All @@ -199,12 +199,12 @@ CADisplay >> viewMorph [

{
#category : #functional,
#'squeak_changestamp' : 'KoPa 7/12/2024 18:11'
#'squeak_changestamp' : 'KoPa 7/12/2024 20:32'
}
CADisplay >> wipeCells [

cells do: [ :eachMorph |
eachMorph delete. ].
cells do: [:eachMorph |
eachMorph delete.].
cells removeAll.

]
42 changes: 17 additions & 25 deletions src/ComputationalArt/CAGame.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -115,36 +115,29 @@ CAGame >> frameDelay: aSecondCount [

]

{
#category : #'initialize-release',
#'squeak_changestamp' : 'KoPa 7/12/2024 19:27'
}
CAGame >> initialize [
]

{
#category : #functional,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:13'
#'squeak_changestamp' : 'KoPa 7/12/2024 20:33'
}
CAGame >> putCellAtRow: aRow andCol: aCol [

| originRow originCol placeRow placeCol |
originRow := aRow - brushSize.
originCol := aCol - brushSize.
1 to: brushSize * 2 - 1
do: [ :rowIndex | 1
to: brushSize * 2 - 1
do: [ :colIndex |
do: [:rowIndex |
1 to: brushSize * 2 - 1
do: [:colIndex |
placeRow := originRow + rowIndex.
placeCol := originCol + colIndex.
(placeRow > 0
and: placeRow < 101
and: placeCol > 0
and: placeCol < 101)
ifTrue: [ grid
and: placeRow < 101
and: placeCol > 0
and: placeCol < 101)
ifTrue: [grid
putCell: activeCellType
atRow: placeRow
andCol: placeCol. ]]].
andCol: placeCol.]]].
screen step.
]

Expand All @@ -159,17 +152,17 @@ CAGame >> setActiveCellTypeTo: aType [

{
#category : #functional,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:14'
#'squeak_changestamp' : 'KoPa 7/12/2024 20:33'
}
CAGame >> skipAhead: aStepCount [

aStepCount timesRepeat: [ ruler applyRules: ruleSet to: grid. ].
aStepCount timesRepeat: [ruler applyRules: ruleSet to: grid.].
screen step.
]

{
#category : #'initialize-release',
#'squeak_changestamp' : 'KoPa 7/12/2024 19:27'
#'squeak_changestamp' : 'KoPa 7/12/2024 20:36'
}
CAGame >> start [

Expand All @@ -195,13 +188,12 @@ CAGame >> start [
maxIterations := 100.
iterationCount := 0.
gameloop := [[iterationCount < maxIterations]
whileTrue: [(Delay forSeconds: frameDelay) wait.
isRunning
ifTrue: [ruler applyRules: ruleSet to: grid.
whileTrue: [
(Delay forSeconds: frameDelay) wait.
isRunning ifTrue: [
ruler applyRules: ruleSet to: grid.
screen step.
iterationCount := iterationCount + 1]].
Transcript show: 'Game loop terminated after ' , maxIterations printString , ' iterations.';
cr] fork
iterationCount := iterationCount + 1.]]] fork.
]

{
Expand Down
58 changes: 17 additions & 41 deletions src/ComputationalArt/CAGrid.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class {

{
#category : #functional,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:18'
#'squeak_changestamp' : 'KoPa 7/12/2024 19:33'
}
CAGrid class >> clear: aGrid [

Expand All @@ -20,72 +20,48 @@ CAGrid class >> clear: aGrid [
numRows := aGrid numRows.
col := #(0 0).
1 to: numRows
do: [:rowIndex | 1
do: [ :rowIndex | 1
to: numCols
do: [:colIndex | aGrid
do: [ :colIndex | aGrid
putCell: col atRandom
atRow: rowIndex
andCol: colIndex]]
andCol: colIndex. ]].
]

{
#category : #functional,
#'squeak_changestamp' : 'Sars 6/16/2024 20:45'
#'squeak_changestamp' : 'KoPa 7/12/2024 19:33'
}
CAGrid class >> fill: aGrid [
| rand numCols numRows |
numCols := aGrid numCols.
numRows := aGrid numRows.
rand := #(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 7 7 6 6 6 5 5 5 5 5 9 8 8).
1
to: numRows
do: [:rowIndex | 1
to: numCols
do: [:colIndex | rowIndex < 45
ifTrue: [aGrid
putCell: rand atRandom
atRow: rowIndex
andCol: colIndex]
ifFalse: [aGrid
putCell: 0
atRow: rowIndex
andCol: colIndex]]]
]
CAGrid class >> fillStone: aGrid [

{
#category : #functional,
#'squeak_changestamp' : 'HaMa 6/20/2024 11:14'
}
CAGrid class >> fillStone: aGrid [
| numCols numRows |
numCols := aGrid numCols.
numRows := aGrid numRows.
1
to: numRows
do: [:rowIndex | 1
1 to: numRows
do: [ :rowIndex | 1
to: numCols
do: [:colIndex | aGrid
do: [ :colIndex | aGrid
putCell: CABlocks stone
atRow: rowIndex
andCol: colIndex]]
andCol: colIndex. ]].
]

{
#category : #functional,
#'squeak_changestamp' : 'HaMa 6/20/2024 11:14'
#'squeak_changestamp' : 'KoPa 7/12/2024 19:33'
}
CAGrid class >> fillTNT: aGrid [
CAGrid class >> fillTNT: aGrid [

| numCols numRows |
numCols := aGrid numCols.
numRows := aGrid numRows.
1
to: numRows
do: [:rowIndex | 1
1 to: numRows
do: [ :rowIndex | 1
to: numCols
do: [:colIndex | aGrid
do: [ :colIndex | aGrid
putCell: CABlocks tnt
atRow: rowIndex
andCol: colIndex]]
andCol: colIndex. ]].
]

{
Expand Down
37 changes: 22 additions & 15 deletions src/ComputationalArtTests/CABlocksTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,38 @@ Class {
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 10:28'
#category : #'initialize-release',
#'squeak_changestamp' : 'KoPa 7/12/2024 20:00'
}
CABlocksTest >> expectedFailures [
^ {#testWrongIndexFail}

^ {#testWrongIndexFail}.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 10:07'
#category : #'initialize-release',
#'squeak_changestamp' : 'KoPa 7/12/2024 19:57'
}
CABlocksTest >> setUp [

blocks := CABlocks new.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 10:07'
#category : #functional,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:57'
}
CABlocksTest >> tearDown [

blocks := nil.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'KoPa 7/12/2024 18:03'
#category : #testing,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:58'
}
CABlocksTest >> testColors [

self assert: Color white equals: (blocks colorAt: CABlocks air).
self assert: Color blue equals: (blocks colorAt: CABlocks water).
self assert: Color yellow equals: (blocks colorAt: CABlocks sand).
Expand All @@ -49,10 +53,11 @@ CABlocksTest >> testColors [
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 10:11'
#category : #testing,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:58'
}
CABlocksTest >> testIndexMethods [

self assert: 0 equals: CABlocks air.
self assert: 1 equals: CABlocks water.
self assert: 2 equals: CABlocks sand.
Expand All @@ -66,10 +71,11 @@ CABlocksTest >> testIndexMethods [
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'KoPa 7/12/2024 18:03'
#category : #testing,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:58'
}
CABlocksTest >> testNames [

self assert: 'air' equals: (blocks nameAt: CABlocks air).
self assert: 'water' equals: (blocks nameAt: CABlocks water).
self assert: 'sand' equals: (blocks nameAt: CABlocks sand).
Expand All @@ -83,9 +89,10 @@ CABlocksTest >> testNames [
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'KoPa 7/12/2024 18:03'
#category : #testing,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:58'
}
CABlocksTest >> testWrongIndexFail [

self assert: 'wall' equals: (blocks nameAt: -1).
]
Loading

0 comments on commit a5a61f8

Please sign in to comment.