public void Render_GivenDeadCell_OutputsDot() { var gameOfLifeBoard = new GameOfLifeBoard(1, 1); var output = _renderer.Render(gameOfLifeBoard); Assert.That(output.First(), Is.EqualTo("-")); }
public void Render_GivenValidNotNullGameboardWithZeroDimensions_ReturnsEmptyList() { var gameOfLifeBoard = new GameOfLifeBoard(0, 0); var output = _renderer.Render(gameOfLifeBoard); Assert.That(!output.Any()); }
public void Render_GivenValidNotNullGameboard_ReturnsLinesOfCorrectWidth() { var gameOfLifeBoard = new GameOfLifeBoard(8, 5); var output = _renderer.Render(gameOfLifeBoard); Assert.That(output.First().Count, Is.EqualTo(8)); }
public void Ctor_GivenDimensions_RowsAreNotNull() { var board = new GameOfLifeBoard(30, 30); Assert.That(board.Board, Is.Not.Null); //Assert.That(board.Board.Count, Is.EqualTo(30)); //Assert.That(board.Board, Is.EqualTo(30)); }
public void Ctor_GivenDimensions_IsNotNull() { var board = new GameOfLifeBoard(30, 30); Assert.That(board, Is.Not.Null); Assert.That(board.Width, Is.EqualTo(30)); Assert.That(board.Height, Is.EqualTo(30)); }
public void Render_GivenAliveCell_OutputsHash() { var gameOfLifeBoard = new GameOfLifeBoard(1, 1, _mockCellGenerator.Object); var output = _renderer.Render(gameOfLifeBoard); Assert.That(output.First(), Is.EqualTo("#")); }
public void Render_EmptyBoardReasonableSize_LooksFine() { var gameOfLifeBoard = new GameOfLifeBoard(20, 20); var output = _renderer.Render(gameOfLifeBoard); foreach (var line in output) { Console.WriteLine(line); } }
public void Ctor_GivenDimensions_CorrectDisplay() { var board = new GameOfLifeBoard(10, 10); var renderer = new GameBoardRenderer(); var output = renderer.Render(board); foreach (var line in output) { Console.WriteLine(line); } }
public void Ctor_GivenDimensionsAndStrategy_GenerateCellsUsingSuppliedStrategy() { var expectedCell = new Cell(); var mockStrategy = new Mock <ICellGenerationStrategy>(); mockStrategy.Setup(x => x.GenerateCells(It.IsAny <int>())).Returns(new List <Cell> { expectedCell }); var board = new GameOfLifeBoard(1, 1, mockStrategy.Object); Assert.That(board.Board[0, 0], Is.EqualTo(expectedCell)); }
public void Step_GivenOneLivingCell_Dies() { var board = new GameOfLifeBoard(1, 1, new StaticListStrategy(new List <Cell> { new Cell { IsAlive = true } })); board.Step(); Assert.That(board.Board[0, 0].IsAlive, Is.False); }
public void Step_GivenMoreThanThreeNeighbours_Dies() { /* * If cell has > 3 living neighbours, cell dies * If cell has 2-3 living neighbours, cell lives */ var board = new GameOfLifeBoard(3, 3, new StaticListStrategy(new List <Cell> { new Cell { IsAlive = true }, new Cell { IsAlive = true }, new Cell { IsAlive = true }, new Cell { IsAlive = true }, new Cell { IsAlive = true }, //This one should die if all alive new Cell { IsAlive = true }, new Cell { IsAlive = true }, new Cell { IsAlive = true }, new Cell { IsAlive = true } })); board.Step(); Assert.That(board.Board[1, 1].IsAlive, Is.False); }
static void Main(string[] args) { var board = new GameOfLifeBoard(50, 50); var renderer = new GameBoardRenderer(); for (int i = 0; i < 100; i++) { var output = renderer.Render(board); Console.Clear(); foreach (var line in output) { Console.WriteLine(line); } Thread.Sleep(500); board.Step(); } }
public List <string> Render(GameOfLifeBoard gameOfLifeBoard) { if (gameOfLifeBoard == null) { throw new ArgumentException("Gameboard cannot be rendered."); } var outputLine = new List <string>(); for (var y = 0; y < gameOfLifeBoard.Height; y++) { var buffer = new StringBuilder(); for (var x = 0; x < gameOfLifeBoard.Width; x++) { var cell = gameOfLifeBoard.Board[x, y]; //Hashes for alive, Dashes for Dead buffer.Append(cell.IsAlive ? "#" : "-"); } outputLine.Add(buffer.ToString()); } return(outputLine); }
public void Step_GiveTwoLivingNeighbours_Lives() { /* * If cell has < 2 living neighbours, cell dies * If cell has 2-3 living neighbours, cell lives */ var board = new GameOfLifeBoard(3, 1, new StaticListStrategy(new List <Cell> { new Cell { IsAlive = true }, //Should die new Cell { IsAlive = true }, //He should live new Cell { IsAlive = true } //Should die })); board.Step(); Assert.That(board.Board[1, 0].IsAlive, Is.True); }
public void Ctor_GivenDimensions_CellsPopulated() { var board = new GameOfLifeBoard(1, 1); Assert.That(board.Board[0, 0], Is.TypeOf <Cell>()); }