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); } }
/// <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; }
public void DefaultConstructor_ExpectedValues() { // Call var board = new GameBoard(); // Assert Assert.AreEqual(10, board.Size); }
public MainWindow() { InitializeComponent(); board = new GameBoard(); bot = new PlayerBot(board); bot.ChooseBoardElement(new Random()); GameBoardControl.Data = board; }
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); }
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); }
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); }
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); }
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); }
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); }