示例#1
0
        public void ToStringShould_ReturnExpectedString_WhenThereIsNoMinesInASize2Board()
        {
            const string expectedString = ". . \n" + ". . \n";
            var          board          = Board.CreateEmptyBoard(2);
            var          minesGenerator = new RandomMinesGenerator();

            minesGenerator.PlaceMines(0, board);
            HintGenerator.SetHints(board);
            Assert.Equal(expectedString, board.ToString());
        }
示例#2
0
        public void ToStringShould_ReturnExpectedString_WhenThereIs1RevealedTopLeftMineInASize2Board()
        {
            var          mineGenerator  = new MockMinesGenerator();
            const string expectedString = "* 1 \n" + "1 1 \n";
            var          board          = Board.CreateEmptyBoard(2);

            mineGenerator.PlaceMines(1, board);
            HintGenerator.SetHints(board);
            board.RevealAllSquares();
            Assert.Equal(expectedString, board.ToString());
        }
示例#3
0
        public void CreateBoard()
        {
            var difficultyValue = SetDifficultyValue();
            var size            = difficultyValue;

            Board = Board.CreateEmptyBoard(size);
            var numberOfMines = difficultyValue;

            _minesGenerator.PlaceMines(numberOfMines, Board);
            HintGenerator.SetHints(Board);
            _output.Write(GameInstruction.DisplayCurrentBoardMessage);
            DisplayBoard();
        }
示例#4
0
        public void ToStringShould_ReturnExpectedString_WhenThereIs1RevealedMineInASize1Board()
        {
            const string expectedHiddenString   = ". \n";
            const string expectedRevealedString = "* \n";
            var          board          = Board.CreateEmptyBoard(1);
            var          minesGenerator = new RandomMinesGenerator();

            minesGenerator.PlaceMines(1, board);
            HintGenerator.SetHints(board);
            Assert.Equal(expectedHiddenString, board.ToString());
            board.RevealAllSquares();
            Assert.Equal(expectedRevealedString, board.ToString());
        }
        public void SetHintsShould_setHintTo0_WhenThereIsOnly1MineSquare()
        {
            var mineGenerator = new RandomMinesGenerator();
            var board         = Board.CreateEmptyBoard(1);

            mineGenerator.PlaceMines(1, board);

            HintGenerator.SetHints(board);
            foreach (var item in board.Squares)
            {
                Assert.Equal(0, item.Hint);
            }
        }
        public void SetHintsShould_Set3HintsWithValue1_WhenThereIs1Mine_InASize2Board()
        {
            var board         = Board.CreateEmptyBoard(2);
            var mineGenerator = new RandomMinesGenerator();

            mineGenerator.PlaceMines(1, board);

            HintGenerator.SetHints(board);

            var squaresWithHintValueOne = board.Squares.Where(item => item.Hint == 1);

            Assert.Equal(3, squaresWithHintValueOne.Count());
        }
        public void SetHintsShould_Set8HintsWithValue1_WhenThereIs1Mine_InTheMiddleOfASize3Board()
        {
            var board          = Board.CreateEmptyBoard(3);
            var centerLocation = new Location(1, 1);
            var square         = board.GetSquare(centerLocation);

            square.SetMine();

            HintGenerator.SetHints(board);

            var squaresWithHintValueOne = board.Squares.Where(item => item.Hint == 1);

            Assert.Equal(8, squaresWithHintValueOne.Count());
        }
        public void SetHintsShould_Set3HintsWithValue1_WhenThereIs1Mine_InTheTopLeftCornerOfASize3Board()
        {
            var board   = Board.CreateEmptyBoard(3);
            var topLeft = new Location(0, 0);
            var square  = board.GetSquare(topLeft);

            square.SetMine();

            HintGenerator.SetHints(board);

            var squaresWithHintValueOne  = board.Squares.Where(item => item.Hint == 1);
            var squaresWithHintValueZero = board.Squares.Where(item => item.Hint == 0);

            Assert.Equal(3, squaresWithHintValueOne.Count());
            Assert.Equal(6, squaresWithHintValueZero.Count());
        }
        public void SetHintsShould_Set2HintsWithValue2_WhenThereAre2Mines_InTheTopLineOfASize2Board()
        {
            var board         = Board.CreateEmptyBoard(2);
            var topLeft       = new Location(0, 0);
            var topLeftSquare = board.GetSquare(topLeft);

            topLeftSquare.SetMine();
            var topRight       = new Location(0, 1);
            var topRightSquare = board.GetSquare(topRight);

            topRightSquare.SetMine();

            HintGenerator.SetHints(board);

            var squaresWithHintValueTwo = board.Squares.Where(item => item.Hint == 2);

            Assert.Equal(2, squaresWithHintValueTwo.Count());
        }