Skip to content

Commit

Permalink
CAGrid tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HagenMarin committed Jun 20, 2024
1 parent e958770 commit 04ddf16
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 5 deletions.
46 changes: 41 additions & 5 deletions src/ComputationalArt/CAGrid.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ Class {
#category : #ComputationalArt
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 10:48'
}
CAGrid class >> clear: aGrid [
| numCols numRows col |
numCols := aGrid numCols.
numRows := aGrid numRows.
col := #(0 0).
1
to: numRows
do: [:rowIndex | 1
to: numCols
do: [:colIndex | aGrid
putCell: col atRandom
atRow: rowIndex
andCol: colIndex]]
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/16/2024 20:45'
Expand All @@ -35,19 +54,36 @@ CAGrid class >> fill: aGrid [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/16/2024 20:45'
#'squeak_changestamp' : 'HaMa 6/20/2024 11:14'
}
CAGrid class >> fillTNTest: aGrid [
| numCols numRows col |
CAGrid class >> fillStone: aGrid [
| numCols numRows |
numCols := aGrid numCols.
numRows := aGrid numRows.
col := #(3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ).
1
to: numRows
do: [:rowIndex | 1
to: numCols
do: [:colIndex | aGrid
putCell: col atRandom
putCell: CABlocks stone
atRow: rowIndex
andCol: colIndex]]
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 11:14'
}
CAGrid class >> fillTNT: aGrid [
| numCols numRows |
numCols := aGrid numCols.
numRows := aGrid numRows.
1
to: numRows
do: [:rowIndex | 1
to: numCols
do: [:colIndex | aGrid
putCell: CABlocks tnt
atRow: rowIndex
andCol: colIndex]]
]
Expand Down
179 changes: 179 additions & 0 deletions src/ComputationalArtTests/CAGridTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
Class {
#name : #CAGridTest,
#superclass : #TestCase,
#instVars : [
'grid'
],
#category : #ComputationalArtTests
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 10:52'
}
CAGridTest >> expectedFailures [
^ {#testFillEmptyFail}
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 10:37'
}
CAGridTest >> setUp [
grid := CAGrid new.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 10:37'
}
CAGridTest >> tearDown [
grid := nil.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 10:58'
}
CAGridTest >> testDeepCopy [
| numCols numRows copiedGrid|
numCols := grid numCols.
numRows := grid numRows.
CAGrid fill: grid.
copiedGrid := grid deepcopy.
1
to: numRows
do: [:rowIndex | 1
to: numCols
do: [:colIndex | self assert: (copiedGrid getCellAtRow: rowIndex andCol: colIndex) equals: (grid getCellAtRow: rowIndex andCol: colIndex)]].
copiedGrid putCell:-1 atRow: 1 andCol: 1.
self assert: -1 < (grid getCellAtRow: 1 andCol: 1).
CAGrid clear: grid.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 10:53'
}
CAGridTest >> testFillEmptyFail [
| numCols numRows |
numCols := grid numCols.
numRows := grid numRows.
CAGrid fill: grid.
1
to: numRows
do: [:rowIndex | 1
to: numCols
do: [:colIndex | self assert: CABlocks air equals: (grid getCellAtRow: rowIndex andCol: colIndex)]].
CAGrid clear: grid.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 11:14'
}
CAGridTest >> testFillStone [
| numCols numRows |
numCols := grid numCols.
numRows := grid numRows.
CAGrid fillStone: grid.
1
to: numRows
do: [:rowIndex | 1
to: numCols
do: [:colIndex | self assert: CABlocks stone equals: (grid getCellAtRow: rowIndex andCol: colIndex)]].
CAGrid clear: grid.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 11:15'
}
CAGridTest >> testFillTNT [
| numCols numRows |
numCols := grid numCols.
numRows := grid numRows.
CAGrid fillTNT: grid.
1
to: numRows
do: [:rowIndex | 1
to: numCols
do: [:colIndex | self assert: CABlocks tnt equals: (grid getCellAtRow: rowIndex andCol: colIndex)]].
CAGrid clear: grid.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 11:05'
}
CAGridTest >> testGetNeighbors [
| numCols numRows neighbors|
numCols := 3.
numRows := 3.
CAGrid clear: grid.
neighbors := grid getNeighborsOfCellAtRow: 2 andCol: 2.
1
to: numRows
do: [:rowIndex | 1
to: numCols
do: [:colIndex | self assert: CABlocks air equals: (neighbors at: rowIndex at: colIndex)]].
grid putCell: 1 atRow: 2 andCol: 2.
neighbors := grid getNeighborsOfCellAtRow: 2 andCol: 2.
self assert: 1 equals: (neighbors at: 2 at: 2).
CAGrid clear: grid.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 11:17'
}
CAGridTest >> testGrid [
|gridMatrix|
CAGrid clear: grid.
grid putCell: 1 atRow: 1 andCol: 1.
gridMatrix := grid grid.
self assert: 1 equals: (gridMatrix at: 1 at: 1).
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 11:07'
}
CAGridTest >> testNumCols [
self assert: 100 equals: grid numCols.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 11:07'
}
CAGridTest >> testNumRows [
self assert: 100 equals: grid numRows.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 11:02'
}
CAGridTest >> testPutCellGetCell [
grid putCell: 1 atRow: 1 andCol: 1.
self assert: 1 equals: (grid getCellAtRow: 1 andCol: 1).
CAGrid clear: grid.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/20/2024 11:13'
}
CAGridTest >> testclear [
| numCols numRows |
numCols := grid numCols.
numRows := grid numRows.
CAGrid fillStone: grid.
CAGrid clear: grid.
1
to: numRows
do: [:rowIndex | 1
to: numCols
do: [:colIndex | self assert: CABlocks air equals: (grid getCellAtRow: rowIndex andCol: colIndex)]].
]

0 comments on commit 04ddf16

Please sign in to comment.