public void AreaPopShouldPopCorrectlyOnCorner()
        {
            var effect = new AreaPopEffect();
             var board = new Board(8, 8, new RandomGenerator());
             effect.Pop(0, 0, board);

             for (int row = 0; row < 8; row++)
             {
                 for (int col = 0; col < 8; col++)
                 {
                     if (row < 2 && col < 2)
                     {
                         if (board[row, col] != Balloon.Default)
                         {
                             Assert.Fail("Balloons didn't pop.");
                         }
                     }
                     else
                     {
                         if (board[row, col] == Balloon.Default)
                         {
                             Assert.Fail("Too many balloons popped.");
                         }
                     }
                 }
             }
        }
Exemplo n.º 2
0
        public void BoardContainsDifferentValuesAfterResetIsExecuted()
        {
            var size = 5;
            var board = new Board(size, size, this.randomGenerator);

            var oldBoard = new int[size, size];

            for (int i = 0; i < board.Rows; i++)
            {
                for (int j = 0; j < board.Cols; j++)
                {
                    oldBoard[i, j] = board[i, j].Value;
                }
            }

            board.Reset();

            var matricesAreDifferent = false;

            for (int i = 0; i < board.Rows; i++)
            {
                for (int j = 0; j < board.Cols; j++)
                {
                    if (oldBoard[i, j] != board[i, j].Value)
                    {
                        matricesAreDifferent = true;
                    }
                }
            }

            Assert.IsTrue(matricesAreDifferent);
        }
Exemplo n.º 3
0
        public void BoardIsValidPopShouldReturnFalseWhenNullBalloonPositionsArePassed()
        {
            var board = new Board(5, 5, this.randomGenerator);

            board[1, 1] = null;

            Assert.IsFalse(board.IsValidPop(1, 1));
        }
        public void BfsEffectShouldPopAtLeastOneBalloon()
        {
            var effect = new BfsEffect();
            var board = new Board(8, 8, new RandomGenerator());
            effect.Pop(4, 4, board);

            var hasPoppedBalloon = false;

            for (int col = 0; col < 8; col++)
            {
                if (board[0, col] == Balloon.Default)
                {
                    hasPoppedBalloon = true;
                    break;
                }
            }

            Assert.IsTrue(hasPoppedBalloon);
        }
Exemplo n.º 5
0
        public void BoardRestoreMementoShouldRestoreBoardToPreviousState()
        {
            var board = new Board(5, 5, this.randomGenerator);
            var memento = board.SaveMemento();

            board[0, 0] = null;
            board[1, 1] = null;
            board[1, 0] = null;

            board.RestoreMemento(memento);

            if (board[0, 0] != null && board[1, 1] != null && board[1, 0] != null)
            {
                Assert.Pass();
            }
            else
            {
                Assert.Fail();
            }
        }
Exemplo n.º 6
0
        public void BoardIsValidPopShouldReturnTrueWhenExistingValuesAreProvided()
        {
            var board = new Board(5, 5, this.randomGenerator);

            Assert.IsTrue(board.IsValidPop(3, 3));
        }
Exemplo n.º 7
0
        public void BoardIsValidPopShouldReturnFalseWhenInvalidArgumentsAreProvided()
        {
            var board = new Board(5, 5, this.randomGenerator);

            Assert.IsFalse(board.IsValidPop(6, 6));
        }
Exemplo n.º 8
0
 public void BoardWithValidRowsAndColumnsParametersShouldBeCreated(
     [Values(5, 7, 10, 13, 15)] int validSize)
 {
     var board = new Board(validSize, validSize,this.randomGenerator);
 }
Exemplo n.º 9
0
 public void BoardWithValidRowsAndInvalidColumnsParametersShouldThrow()
 {
     var board = new Board(5, 4, this.randomGenerator);
 }
Exemplo n.º 10
0
 public void BoardWithInvalidRowsAndColumnsParametersShouldThrow(
     [Values(1, 3, 16, 17)] int invalidSize)
 {
     var board = new Board(invalidSize, invalidSize, this.randomGenerator);
 }
Exemplo n.º 11
0
        public void BoardUnpoppedBalloonsCountShouldReturnValidAmountWhenThereArePoppedBalloons()
        {
            var size = 5;
            var board = new Board(size, size, this.randomGenerator);

            board[3, 3] = null;
            board[2, 2] = null;

            var balloonsCount = board.UnpoppedBalloonsCount;
            var expected = (size * size) - 2;

            Assert.AreEqual(expected, balloonsCount);
        }
Exemplo n.º 12
0
        public void BoardUnpoppedBalloonsCountShouldReturnInitialAmountOfBalloons()
        {
            var size = 5;
            var board = new Board(size, size, this.randomGenerator);

            var initialBalloonsCount = board.UnpoppedBalloonsCount;
            var expected = size * size;

            Assert.AreEqual(expected, initialBalloonsCount);
        }
Exemplo n.º 13
0
        public void BoardToStringShouldReturnValidStringRepresentation()
        {
            var board = new Board(5, 5, this.randomGenerator);
            var expectedString =
                "    0 1 2 3 4 \r\n    ----------\r\n0 | . 1 1 1 1 | \r\n1 | 1 1 1 1 1 | \r\n2 | 1 1 1 1 1 | \r\n3 | 1 1 1 1 1 | \r\n4 | 1 1 1 1 1 | \r\n    ----------\r\n";

            SetBoardMatrix(board);

            var resultingString = board.ToString();

            Assert.AreEqual(expectedString, resultingString);
        }
Exemplo n.º 14
0
        public void BoardSaveMementoShouldReturnAMemento()
        {
            var board = new Board(5, 5, this.randomGenerator);
            var memento = board.SaveMemento().Board;

            var boardAsMatrix = new IBalloon[5, 5];

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    boardAsMatrix[i, j] = board[i, j];
                }
            }

            var anotherMemento = new Memento(boardAsMatrix).Board;

            Assert.AreEqual(memento, anotherMemento);
        }