Example #1
0
        /// <summary>
        /// Tests the Initialize method for correct input
        /// Expected einitialized cells with correct colors, white colour goes first
        /// </summary>        [TestMethod()]
        public void InitializeTest_CorrectInputWhiteFirst_ReturnedInitializedCellsWithCorrectColors()
        {
            // Arrange
            int width  = 2;
            int height = 3;

            ICell[,] expectedCells =
            {
                { new ChessCell(Colors.White), new ChessCell(Colors.Black), new ChessCell(Colors.White) },
                { new ChessCell(Colors.Black), new ChessCell(Colors.White), new ChessCell(Colors.Black) },
                { new ChessCell(Colors.White), new ChessCell(Colors.Black), new ChessCell(Colors.White) },
            };
            ICell[,] actualCells = new ChessCell[width, height];

            // Act
            ICellInitializer initializer = new ChessBoardCellInitializer(true);

            initializer.Initialize(actualCells);

            // Assert
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    Assert.AreEqual(expectedCells[i, j].Colour, actualCells[i, j].Colour);
                }
            }
        }
Example #2
0
        public void Board_IndexerTest_TestForIncorrectIndex_ExpectedIndexOutOfRangeException()
        {
            // Arrange
            byte             width          = 10;
            byte             height         = 5;
            int              line           = 9;
            int              column         = 6;
            Colors           expectedColour = Colors.White;
            ICellInitializer initializer    = new ChessBoardCellInitializer();
            Board            chessBoard     = new Board(width, height, initializer);

            // Act
            Colors actualColour = chessBoard[line, column].Colour;

            // Assert
            Assert.AreEqual(expectedColour, actualColour);
        }
Example #3
0
        public void Board_InitializeTest_CorrectInput_ReturnNewChessBoardWithCorrectProperties()
        {
            // Arrange
            byte             height      = 5;
            byte             width       = 10;
            ICellInitializer initializer = new ChessBoardCellInitializer();

            // Act
            Board chessBoard = new Board(width, height, initializer);

            // Assert
            AssertAll.Succeed(
                () => Assert.IsNotNull(chessBoard),
                () => Assert.IsInstanceOfType(chessBoard, typeof(IBoard)),
                () => Assert.AreEqual(height, chessBoard.Height),
                () => Assert.AreEqual(width, chessBoard.Width)
                );
        }
Example #4
0
        public void Board_InitializeTest_IncorrectInput_ExpectedArgumentException(
            byte width, byte height)
        {
            // Arrange
            Board chessBoard;

            // Act
            ICellInitializer initializer = new ChessBoardCellInitializer();

            chessBoard = new Board(width, height, initializer);

            // Assert
            AssertAll.Succeed(
                () => Assert.IsNotNull(chessBoard),
                () => Assert.IsInstanceOfType(chessBoard, typeof(IBoard)),
                () => Assert.AreEqual(height, chessBoard.Height),
                () => Assert.AreEqual(width, chessBoard.Width)
                );
        }
Example #5
0
        /// <summary>
        /// Runs the application
        /// </summary>
        /// <param name="args">The arguments from command lines</param>
        /// <returns>Return code: 0 if success, 1 if error occurred</returns>
        public int Run(string[] args)
        {
            try
            {
                byte width;
                byte height;
                bool isWhiteCellFirst;
                Parser.Parse(args, out width, out height, out isWhiteCellFirst);
                ICellInitializer        initializer        = new ChessBoardCellInitializer(isWhiteCellFirst);
                IBoard                  chessBoard         = new Board(height, width, initializer);
                ChessBoardConsoleViewer boardConsoleViewer = new ChessBoardConsoleViewer();
                boardConsoleViewer.DisplayBoard(chessBoard);
            }
            catch (ArgumentException exception)
            {
                Console.WriteLine(exception.Message);
                this.ShowInstructions();
                return((int)ReturnCode.Error);
            }

            return((int)ReturnCode.Success);
        }