Exemple #1
0
        public void ShouldRevealAllNonMineAdjacentCells_WhenRevealCellWithNoAdjacentMine()
        {
            var mineCountState = new List <int>
            {
                0, 0, 0, 0,
                1, 1, 1, 0,
                1, 0, 1, 0,
                1, 1, 1, 0
            };
            var gameBoard = SetupGameBoardWithMineCounts(mineCountState);

            var playCoordinate = new Coordinate(1, 1); // coordinate of a cell with no adjacent mine
            var revealCommand  = new RevealCommand(playCoordinate);

            revealCommand.Execute(gameBoard);

            var result             = gameBoard.BoardState.Select(c => c.CellState);
            var expectedBoardState = new List <CellState>
            {
                CellState.Revealed, CellState.Revealed, CellState.Revealed, CellState.Revealed,
                CellState.Revealed, CellState.Revealed, CellState.Revealed, CellState.Revealed,
                CellState.Unrevealed, CellState.Unrevealed, CellState.Revealed, CellState.Revealed,
                CellState.Unrevealed, CellState.Unrevealed, CellState.Revealed, CellState.Revealed,
            };

            Assert.Equal(expectedBoardState, result);
        }
Exemple #2
0
        public void ShouldThrowInvalidMoveException_WhenExecuteOnAlreadyRevealedCell()
        {
            var revealCoordinate = new Coordinate(1, 1);
            var revealCommand    = new RevealCommand(revealCoordinate);

            // set Cell cellState to 'Revealed' before the reveal command is executed
            var gameBoard = new GameBoard(5, 5);

            gameBoard.GetCell(revealCoordinate).CellState = CellState.Revealed;

            Assert.Throws <InvalidMoveException>(() => revealCommand.Execute(gameBoard));
        }
Exemple #3
0
        public void ShouldSetSelectedCellStateToRevealed_WhenExecuted()
        {
            var revealCoordinate = new Coordinate(1, 1);
            var revealCommand    = new RevealCommand(revealCoordinate);
            var gameBoard        = new GameBoard(5, 5);

            revealCommand.Execute(gameBoard);

            var result = gameBoard.GetCell(revealCoordinate).CellState;

            Assert.Equal(CellState.Revealed, result);
        }