public void AddMinesToTheBoard_CorrectCountOfMinesIsPlanted(int width, int height) { var board = new GameBoard(width, height); board.AddMinesToTheBoard(); var numberOfMines = board.Board.Cast <Cell>().Count(cell => cell.State == State.Mine); Assert.AreEqual(board.RemainingMineCount, numberOfMines); }
public void AddMinesToTheBoard_MinesCountInRange(int width, int height) { var board = new GameBoard(width, height); board.AddMinesToTheBoard(); var min = Math.Ceiling(width * height * 0.2); var max = Math.Floor(width * height * 0.6); Assert.GreaterOrEqual(board.RemainingMineCount, min); Assert.LessOrEqual(board.RemainingMineCount, max); }
public void AddMinesToTheBoard_CorrectNumberOfMinesAroundEveryCell(int width, int height) { var gameBoard = new GameBoard(width, height); gameBoard.AddMinesToTheBoard(); var board = gameBoard.Board; for (int row = 0; row < width; row++) { for (int column = 0; column < height; column++) { var numberOfMinesAround = 0; if (board[row, column].State != State.MinesAround) { continue; } var actualCellMinesAround = board[row, column].MinesAround; for (var i = 0; i < 8; i++) { int xDir = Helper.Directions[i, 0]; int yDir = Helper.Directions[i, 1]; if (Helper.CellIsOutOfTheBoardRange(xDir, yDir, row, column, width, height)) { continue; } if (board[row + yDir, column + xDir].State == State.Mine) { numberOfMinesAround++; } } Assert.AreEqual(actualCellMinesAround, numberOfMinesAround); } } }