예제 #1
0
        public void TestCellValue_Reveal()
        {
            MinesweeperCell cell = new MinesweeperCell('A', false);

            cell.Reveal();
            Assert.AreEqual(true, cell.IsRevealed);
        }
예제 #2
0
        public void GetCell_TestWithValidCellPosition()
        {
            int             gridRows = 10, gridCols = 10, minesCount = 4;
            MinesweeperGrid grid = new MinesweeperGrid(gridRows, gridCols, minesCount);
            MinesweeperCell cell = grid.GetCell(1, 1);

            Assert.AreEqual(MinesweeperCell.EmptyCell, cell.Value);
        }
예제 #3
0
 public void GetCell_TestWithInvalidCellPosition_ShouldThrowException()
 {
     int             gridRows = 10, gridCols = 10, minesCount = 4;
     MinesweeperGrid grid = new MinesweeperGrid(gridRows, gridCols, minesCount);
     MinesweeperCell cell = grid.GetCell(10, 1);
 }
예제 #4
0
 private void _populateBoard()
 {
     var rand = new Random();
     var mineProbability = (double) NumMines / ( Width * Height );
     var mined = new MinesweeperCell[NumMines];
     var currNumMines = 0;
     for (var i = 0; i < Height; i++)
     {
         for (var j = 0; j < Width; j++)
         {
             var index = i * Width + j;
             if (index < NumMines)
             {
                 var cell = new MinesweeperCell(i, j, CellType.Mined);
                 this[i, j] = cell;
                 mined[currNumMines] = cell;
                 currNumMines++;
                 continue;
             }
             if (rand.NextDouble() < (double) NumMines / index)
             {
                 //swap current cell randomly into the list of mined cells
                 var select = rand.Next(mined.Length);
                 mined[select].Type = CellType.Safe;
                 this[i, j] = new MinesweeperCell(i, j, CellType.Mined);
                 mined[select] = this[i, j];
                 continue;
             }
             this[i, j] = new MinesweeperCell(i, j, CellType.Safe);
         }
     }
 }
예제 #5
0
        public void TestGetCellValue_When_Not_Revealed()
        {
            MinesweeperCell cell = new MinesweeperCell('A', false);

            Assert.AreEqual('?', cell.GetCellValue);
        }
예제 #6
0
        public void TestCell_Constructor_With_Params_IsRevealed()
        {
            MinesweeperCell cell = new MinesweeperCell('A', true);

            Assert.AreEqual(true, cell.IsRevealed);
        }
예제 #7
0
        public void TestCell_Constructor_With_Params_Value()
        {
            MinesweeperCell cell = new MinesweeperCell('A', true);

            Assert.AreEqual('A', cell.Value);
        }