Exemplo n.º 1
0
        public void TestFillWithRandomMines_AreMinesOnRandomPositionsEachTime()
        {
            Field gameField = new Field();

            gameField.FillWithRandomMines();
            string[,] firstMatrix = gameField.Matrix;

            gameField.Initialize();
            gameField.FillWithRandomMines();
            string[,] secondMatrix = gameField.Matrix;

            bool areDifferent = false;
            for (int i = 0; i < gameField.Rows; i++)
            {
                for (int j = 0; j < gameField.Cols; j++)
                {
                    if (firstMatrix[i, j] != secondMatrix[i, j])
                    {
                        areDifferent = true;
                    }
                }
            }

            Assert.AreEqual(true, areDifferent);
        }
Exemplo n.º 2
0
        public void TestUpdate_IsUpdateCorrectSecondCheck()
        {
            Random fixedRnd = new Random(5);
            Field gameField = new Field();
            Type fieldType = typeof(Field);

            var fieldRandom = fieldType.GetField("random", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldRandom.SetValue(gameField, fixedRnd);
            gameField.FillWithRandomMines();

            int cellRow = 3;
            int cellCol = 1;
            gameField.Update(cellCol, cellCol);

            int adjacentMinesCount = 5;
            bool isUpdatedCorrectly = gameField.Matrix[cellRow, cellCol] != adjacentMinesCount.ToString();

            Assert.AreEqual(true, isUpdatedCorrectly);
        }
Exemplo n.º 3
0
        public void TestIsMine_InvalidRowLessThanMin()
        {
            int cellRow = -1;
            int cellCol = 5;

            Field gameField = new Field();
            gameField.FillWithRandomMines();

            bool isMine = gameField.IsMine(cellRow, cellCol);
        }
Exemplo n.º 4
0
        public void TestUpdate_IsMatrixUpdated()
        {
            Random fixedRnd = new Random(5);

            int cellRow = fixedRnd.Next(0, 5) + 1;
            int cellCol = fixedRnd.Next(0, 10) + 1;

            Field gameField = new Field();
            Type fieldType = typeof(Field);

            fixedRnd = new Random(5);

            var fieldRandom = fieldType.GetField("random", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldRandom.SetValue(gameField, fixedRnd);

            gameField.FillWithRandomMines();
            gameField.Update(cellRow, cellCol);
            bool isUpdated = gameField.Matrix[cellRow, cellCol] != string.Empty && gameField.Matrix[cellRow, cellCol] != "*";

            Assert.AreEqual(true, isUpdated);
        }
Exemplo n.º 5
0
        public void TestIsMine_InvalidRowGreaterThanMax()
        {
            int cellRow = 7;
            int cellCol = 5;

            Field gameField = new Field();
            gameField.FillWithRandomMines();

            bool isMine = gameField.IsMine(cellRow, cellCol);
        }
Exemplo n.º 6
0
        public void TestIsMine_InvalidRowAndCol()
        {
            int cellRow = 13;
            int cellCol = -2;

            Field gameField = new Field();
            gameField.FillWithRandomMines();

            bool isMine = gameField.IsMine(cellRow, cellCol);
        }
Exemplo n.º 7
0
        public void TestIsMine_CellHasMine()
        {
            Random fixedRnd = new Random(5);

            int cellRow = fixedRnd.Next(0, 5);
            int cellCol = fixedRnd.Next(0, 10);

            Field gameField = new Field();
            Type fieldType = typeof(Field);

            fixedRnd = new Random(5);

            var fieldRandom = fieldType.GetField("random", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldRandom.SetValue(gameField, fixedRnd);

            gameField.FillWithRandomMines();

            bool isMine = gameField.IsMine(cellRow, cellCol);

            Assert.AreEqual(true, isMine);
        }
Exemplo n.º 8
0
        public void TestInitialize_IsMatrixInitialized()
        {
            Field gameField = new Field();

            gameField.FillWithRandomMines();
            gameField.Initialize();

            bool isInitialized = true;

            for (int i = 0; i < gameField.Rows; i++)
            {
                for (int j = 0; j < gameField.Cols; j++)
                {
                    if (gameField.Matrix[i, j] != string.Empty)
                    {
                        isInitialized = false;
                        break;
                    }
                }
            }

            Assert.AreEqual(true, isInitialized);
        }
Exemplo n.º 9
0
        public void TestFillWithRandomMines_AreMinesWithSpecifiedCount()
        {
            Field gameField = new Field();
            gameField.FillWithRandomMines();

            int currentMinesCount = 0;
            string mine = "*";

            for (int i = 0; i < gameField.Rows; i++)
            {
                for (int j = 0; j < gameField.Cols; j++)
                {
                    if (gameField.Matrix[i, j] == mine)
                    {
                        currentMinesCount++;
                    }
                }
            }

            int minesCountNeeded = 15;
            Assert.AreEqual(minesCountNeeded, currentMinesCount);
        }