1- import GridTesting . _
1+
22import org .scalatest .{FeatureSpec , GivenWhenThen , Matchers }
33
44import scala .collection .mutable
55
6- class GameStepSpec extends FeatureSpec with Matchers with GivenWhenThen {
6+ class GameStepSpec extends FeatureSpec with Matchers with GivenWhenThen with GridFixture {
77
88 feature(" Each game step applies the rules to all applicable cells." ) {
99
@@ -65,10 +65,10 @@ class GameStepSpec extends FeatureSpec with Matchers with GivenWhenThen {
6565 val randomGroupingOfLiveCells = randomNeighborhood(randomCell(), 5 )
6666
6767 val grid = new Grid (randomGroupingOfLiveCells)
68- val liveCellNeighborCountsBeforeRules = countLiveNeighbors(grid, randomGroupingOfLiveCells)
68+ val liveCellLiveNeighborCountsBeforeRules = countLiveNeighbors(grid, randomGroupingOfLiveCells)
6969
7070 val deadCellsWhereRulesApply = getDeadNeighbors(randomGroupingOfLiveCells)
71- val deadCellNeighborCountsBeforeRules = countLiveNeighbors(grid, deadCellsWhereRulesApply)
71+ val deadCellLiveNeighborCountsBeforeRules = countLiveNeighbors(grid, deadCellsWhereRulesApply)
7272
7373 And (" a rule that all live cells die and their dead neighbors become alive" )
7474 val rules = new InvertCellsRules with NeighborCountTracking
@@ -78,8 +78,8 @@ class GameStepSpec extends FeatureSpec with Matchers with GivenWhenThen {
7878 val nextGrid = game.step(grid)
7979
8080 Then (" live neighbor counts reflect the original counts and not any cell deaths or births" )
81- rules.liveNeighborCounts shouldBe liveCellNeighborCountsBeforeRules
82- rules.deadNeighborCounts shouldBe deadCellNeighborCountsBeforeRules
81+ rules.liveCellLiveNeighborCounts shouldBe liveCellLiveNeighborCountsBeforeRules
82+ rules.deadCellLiveNeighborCounts shouldBe deadCellLiveNeighborCountsBeforeRules
8383
8484 And (" all live cells are now dead and dead neighbors are now alive" )
8585 nextGrid.liveCells.intersect(randomGroupingOfLiveCells) shouldBe empty
@@ -100,16 +100,16 @@ class GameStepSpec extends FeatureSpec with Matchers with GivenWhenThen {
100100 }
101101
102102 private trait NeighborCountTracking extends Rules {
103- val liveNeighborCounts = mutable.Map [Cell , Int ]()
104- val deadNeighborCounts = mutable.Map [Cell , Int ]()
103+ val liveCellLiveNeighborCounts = mutable.Map [Cell , Int ]()
104+ val deadCellLiveNeighborCounts = mutable.Map [Cell , Int ]()
105105
106106 abstract override def isLiveCellSurviving (cell : Cell , liveNeighbors : Int ): Boolean = {
107- liveNeighborCounts += (cell -> liveNeighbors)
107+ liveCellLiveNeighborCounts += (cell -> liveNeighbors)
108108 super .isLiveCellSurviving(cell, liveNeighbors)
109109 }
110110
111111 abstract override def isDeadCellReviving (cell : Cell , liveNeighbors : Int ): Boolean = {
112- deadNeighborCounts += (cell -> liveNeighbors)
112+ deadCellLiveNeighborCounts += (cell -> liveNeighbors)
113113 super .isDeadCellReviving(cell, liveNeighbors)
114114 }
115115 }
0 commit comments