public void DeadCell_ExactlyThreeLiveNeighbours_BecomesLiveByReproduction() { Cellstate currentState = Cellstate.Dead; int liveNeghbours = 3; Cellstate result = LifeRules.GetNewState(currentState, liveNeghbours); Assert.AreEqual(Cellstate.Alive, result); }
public void LiveCell_TwoOrThreeLiveNeighbours_LivestoNextGeneration() { Cellstate currentState = Cellstate.Alive; int liveNeghbours = 3; Cellstate result = LifeRules.GetNewState(currentState, liveNeghbours); Assert.AreEqual(Cellstate.Alive, result); }
public void LiveCell_MoreThanThreeLiveNeighbours_DiesByOverpopulation() { Cellstate currentState = Cellstate.Alive; int liveNeghbours = 4; Cellstate result = LifeRules.GetNewState(currentState, liveNeghbours); Assert.AreEqual(Cellstate.Dead, result); }
public void AnyLiveCellWithFewerthanTwoLiveNeighborsDiesAsIfByUnderPopulation() { Cellstate currentState = Cellstate.Alive; int liveNeighbours = 1; Cellstate result = LifeRules.GetNewState(currentState, liveNeighbours); Assert.AreEqual(Cellstate.Dead, result); }
public static Cellstate GetNewState(Cellstate currentState, int liveNeighbours) { if (currentState == Cellstate.Alive && liveNeighbours < 2) { currentState = Cellstate.Dead; } if (currentState == Cellstate.Alive && liveNeighbours > 3) { currentState = Cellstate.Dead; } if (currentState == Cellstate.Dead && liveNeighbours == 3) { currentState = Cellstate.Alive; } return(currentState); }