Skip to content

Commit

Permalink
Merge pull request #64 from hpi-swa-teaching/feat/ls/rules-for-rules
Browse files Browse the repository at this point in the history
added tests for deterministic rules
  • Loading branch information
lasumn authored Jun 23, 2024
2 parents b7b13e5 + 8a2a525 commit 6240413
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions src/ComputationalArtTests/CARulesTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Class {
#name : #CARulesTest,
#superclass : #TestCase,
#instVars : [
'grid',
'ruleSet',
'ruler'
],
#category : #ComputationalArtTests
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/23/2024 17:33'
}
CARulesTest >> setUp [
grid := CAGrid new.
ruler := CARuler new.
ruleSet := OrderedCollection new.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/23/2024 18:15'
}
CARulesTest >> testRuleFallDown [
|newGrid|

ruleSet add: CARuleFallDownEX new.
grid putCell: CABlocks water atRow: 10 andCol: 10.
grid putCell: CABlocks algae atRow: 10 andCol: 20.
grid putCell: CABlocks fire atRow: 10 andCol: 30.
grid putCell: CABlocks fish atRow: 10 andCol: 40.

newGrid := ruler applyRules: ruleSet to: grid.

self assert: ((newGrid getCellAtRow: 10 andCol: 10) = CABlocks air).
self assert: ((newGrid getCellAtRow: 10 andCol: 20) = CABlocks air).
self assert: ((newGrid getCellAtRow: 10 andCol: 30) = CABlocks air).
self assert: ((newGrid getCellAtRow: 10 andCol: 40) = CABlocks air).

self assert: ((newGrid getCellAtRow: 11 andCol: 10) = CABlocks water).
self assert: ((newGrid getCellAtRow: 11 andCol: 20) = CABlocks algae).
self assert: ((newGrid getCellAtRow: 11 andCol: 30) = CABlocks fire).
self assert: ((newGrid getCellAtRow: 11 andCol: 40) = CABlocks fish).

ruleSet removeAll.
CAGrid clear: grid.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/23/2024 18:21'
}
CARulesTest >> testRuleRise [
|newGrid|

ruleSet add: CARuleRiseEX new.
grid putCell: CABlocks smoke atRow: 10 andCol: 10.

newGrid := ruler applyRules: ruleSet to: grid.

self assert: ((newGrid getCellAtRow: 10 andCol: 10) = CABlocks air).
self assert: ((newGrid getCellAtRow: 9 andCol: 10) = CABlocks smoke).

ruleSet removeAll.
CAGrid clear: grid.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/23/2024 18:31'
}
CARulesTest >> testRuleSink [
|newGrid|

ruleSet add: CARuleSinkEX new.
grid putCell: CABlocks sand atRow: 10 andCol: 10.
grid putCell: CABlocks sand atRow: 10 andCol: 20.
grid putCell: CABlocks fire atRow: 11 andCol: 10.
grid putCell: CABlocks water atRow: 11 andCol: 20.

newGrid := ruler applyRules: ruleSet to: grid.

self assert: ((newGrid getCellAtRow: 10 andCol: 10) = CABlocks fire).
self assert: ((newGrid getCellAtRow: 10 andCol: 20) = CABlocks water).

self assert: ((newGrid getCellAtRow: 11 andCol: 10) = CABlocks sand).
self assert: ((newGrid getCellAtRow: 11 andCol: 20) = CABlocks sand).

ruleSet removeAll.
CAGrid clear: grid.
]

0 comments on commit 6240413

Please sign in to comment.