예제 #1
0
        public void MarkNo_UpdateGameBoardState()
        {
            // Setup
            var board = new GameBoard();

            var rowIndex = 4;
            var columnIndex = 3;

            // Call
            board.MarkNo(rowIndex, columnIndex);

            // Assert
            Assert.AreEqual(ElementState.NeitherRowNorColumn, board.Elements[rowIndex, columnIndex].State);

            // All other elements in that row update to 'NotRow'
            foreach (int index in Enumerable.Range(0, board.Size).Except(new[] { columnIndex }))
            {
                Assert.AreEqual(ElementState.NotRow, board.Elements[rowIndex, index].State);
            }

            // All other elements in that column update to 'NotColumn'
            foreach (int index in Enumerable.Range(0, board.Size).Except(new[] { rowIndex }))
            {
                Assert.AreEqual(ElementState.NotColumn, board.Elements[index, columnIndex].State);
            }
        }
예제 #2
0
        /// <summary>
        /// Instantiates a new instance of <see cref="PlayerBot"/> to play with a specified board.
        /// </summary>
        /// <param name="board">The game board to play with.</param>
        public PlayerBot(GameBoard board)
        {
            this.board = board;

            chosenHorizontalIndex = -1;
            chosenVeritcalIndex = -1;
        }
예제 #3
0
        public void DefaultConstructor_ExpectedValues()
        {
            // Call
            var board = new GameBoard();

            // Assert
            Assert.AreEqual(10, board.Size);
        }
예제 #4
0
        public MainWindow()
        {
            InitializeComponent();

            board = new GameBoard();
            bot = new PlayerBot(board);
            bot.ChooseBoardElement(new Random());

            GameBoardControl.Data = board;
        }
예제 #5
0
        public void MarkYes_ElementStateChangesToYes()
        {
            // Setup
            var board = new GameBoard();

            var rowIndex = 0;
            var columnIndex = 0;

            // Call
            board.MarkYes(rowIndex, columnIndex);

            // Assert
            Assert.AreEqual(ElementState.Yes, board.Elements[rowIndex, columnIndex].State);
        }
예제 #6
0
        public void AskLocation_NoMatches_ReturnFalse()
        {
            // Setup
            var board = new GameBoard();

            var bot = new PlayerBot(board);
            bot.ChooseBoardElement(new Random(1));

            // Call
            var answer = bot.AskLocation(0, 0);

            // Assert
            Assert.IsFalse(answer);
        }
예제 #7
0
        public void AskLocation_BeforeChosenBoardElement_ThrowInvalidOperationException()
        {
            // Setup
            var board = new GameBoard();

            var bot = new PlayerBot(board);

            // Call
            TestDelegate call = () => bot.AskLocation(0, 0);

            // Assert
            var message = Assert.Throws<InvalidOperationException>(call).Message;
            Assert.AreEqual("But must have chosen a location first (call 'PlayerBot.ChooseBoardElement()') before calling this method.", message);
        }
예제 #8
0
        public void AskLocation_InvalidIndexes_ThrowArgumentOutOfRangeException(
            int horizontal, int vertical)
        {
            // Setup
            var board = new GameBoard();

            var bot = new PlayerBot(board);
            bot.ChooseBoardElement(new Random());

            // Call
            TestDelegate call = () => bot.AskLocation(horizontal, vertical);

            // Assert
            Assert.Throws<ArgumentOutOfRangeException>(call);
        }
예제 #9
0
        public void AskLocation_AtLocation_ReturnTrue()
        {
            // Setup
            var seed = 2;
            var inputRandom = new Random(seed);
            var referenceRandom = new Random(seed);
            var board = new GameBoard();

            var bot = new PlayerBot(board);
            bot.ChooseBoardElement(inputRandom);

            // Call
            var locationIndex = referenceRandom.Next(0, board.Size);
            var location2Index = referenceRandom.Next(0, board.Size);
            var answer = bot.AskLocation(locationIndex, location2Index);

            // Assert
            Assert.IsTrue(answer);
        }
예제 #10
0
        public void AskLocation_ElementWithSameSecondaryElementValue_ReturnTrue()
        {
            // Setup
            var seed = 2;
            var inputRandom = new Random(seed);
            var referenceRandom = new Random(seed);
            var board = new GameBoard();

            var locationIndex = referenceRandom.Next(0, board.Size);
            var location2Index = referenceRandom.Next(0, board.Size);
            var expectedChosenElement = board.Elements[locationIndex, location2Index];

            int inputRowIndex = -1, intputColumnIndex = -1;
            for (int i = 0; i < board.Size; i++)
            {
                for (int j = 0; j < board.Size; j++)
                {
                    if (expectedChosenElement.SecondaryElementValue == board.Elements[i, j].SecondaryElementValue)
                    {
                        inputRowIndex = i;
                        intputColumnIndex = j;
                    }
                }
            }

            var bot = new PlayerBot(board);
            bot.ChooseBoardElement(inputRandom);

            // Call

            var answer = bot.AskLocation(inputRowIndex, intputColumnIndex);

            // Assert
            Assert.IsTrue(answer);
        }