public void AssignCellOwnerTest() { // make sure that a cell can be assigned as either computer or human // also be sure that only cell within range may be set // many TDD purists argue these are all separate tests // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); ticTacToeGame.IdentifyCellOwner(0, 0).ShouldBe(CellOwners.Open); // _ticTacToeCells should now be initialized to open // act ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Human); ticTacToeGame.AssignCellOwner(0, 1, CellOwners.Computer); ticTacToeGame.AssignCellOwner(0, 11, CellOwners.Computer); // should not do anything ticTacToeGame.AssignCellOwner(0, -1, CellOwners.Computer); // should not do anything // assert ticTacToeGame.IdentifyCellOwner(0, 0).ShouldBe(CellOwners.Human); ticTacToeGame.IdentifyCellOwner(0, 1).ShouldBe(CellOwners.Computer); ticTacToeGame.IdentifyCellOwner(0, 2).ShouldBe(CellOwners.Open); ticTacToeGame.IdentifyCellOwner(0, 11).ShouldBe(CellOwners.Error); // out of bounds ticTacToeGame.IdentifyCellOwner(0, -1).ShouldBe(CellOwners.Error); ticTacToeGame.IdentifyCellOwner(0, 3).ShouldBe(CellOwners.Open); ticTacToeGame.IdentifyCellOwner(3, 0).ShouldBe(CellOwners.Open); ticTacToeGame.CheckForWinner().ShouldBeFalse(); // no winner yet ticTacToeGame.Winner.ShouldBe(CellOwners.Open); // winner property should now be Open ticTacToeGame.IdentifyWinner().ShouldBeEmpty(); // there is no winner }
public void NoWinnerFound() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); // act /* * X O X * X O X * O X O */ ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Human); ticTacToeGame.AssignCellOwner(0, 1, CellOwners.Computer); ticTacToeGame.AssignCellOwner(0, 2, CellOwners.Human); ticTacToeGame.AssignCellOwner(2, 0, CellOwners.Computer); ticTacToeGame.AssignCellOwner(2, 1, CellOwners.Human); ticTacToeGame.AssignCellOwner(2, 2, CellOwners.Computer); ticTacToeGame.AssignCellOwner(1, 0, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 1, CellOwners.Computer); ticTacToeGame.AssignCellOwner(1, 2, CellOwners.Human); // assert ticTacToeGame.CheckForWinner().ShouldBeFalse(); // no winner ticTacToeGame.Winner.ShouldBe(CellOwners.Open); // winner property should be Open ticTacToeGame.IdentifyWinner().ShouldBeEmpty(); // there is no winner }
public void AutoPlayComputerWinnerTest() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); // act ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(0, 1, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(0, 3, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(1, 0, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(1, 2, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(1, 3, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(3, 4, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(4, 1, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(4, 2, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(4, 3, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); // assert ticTacToeGame.CheckForWinner().ShouldBeTrue(); ticTacToeGame.Winner.ShouldBe(CellOwners.Computer); }
public void WinnerHuman() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 0, CellOwners.Computer); ticTacToeGame.AssignCellOwner(0, 1, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 1, CellOwners.Computer); ticTacToeGame.AssignCellOwner(0, 2, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 2, CellOwners.Computer); ticTacToeGame.AssignCellOwner(0, 3, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 3, CellOwners.Computer); ticTacToeGame.CheckForWinner().ShouldBeFalse(); // no winner --- yet ticTacToeGame.AssignCellOwner(0, 4, CellOwners.Human); ticTacToeGame.CheckForWinner().ShouldBeTrue(); ticTacToeGame.Winner.ShouldBe(CellOwners.Human); // winner property should be Human ticTacToeGame.IdentifyWinner().ShouldBe(ticTacToeGame.PlayerName); ticTacToeGame.PlayerName = ""; // should not happen, but it could! ticTacToeGame.IdentifyWinner().ShouldBe("Unnamed Human"); }
public void WinnerComputer() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); // act /* * X O X * O X * O */ ticTacToeGame.AssignCellOwner(0, 3, CellOwners.Human); ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Computer); ticTacToeGame.AssignCellOwner(0, 2, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 1, CellOwners.Computer); ticTacToeGame.AssignCellOwner(1, 2, CellOwners.Human); ticTacToeGame.AssignCellOwner(3, 3, CellOwners.Computer); ticTacToeGame.AssignCellOwner(1, 4, CellOwners.Human); ticTacToeGame.CheckForWinner().ShouldBeFalse(); // no winner --- yet ticTacToeGame.AssignCellOwner(4, 4, CellOwners.Computer); ticTacToeGame.CheckForWinner().ShouldBeTrue(); ticTacToeGame.Winner.ShouldBe(CellOwners.Computer); ticTacToeGame.IdentifyWinner().ShouldBe("Computer"); }
public void WinnerComputer() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); // act ticTacToeGame.AssignCellOwner(0, 2, CellOwners.Computer); ticTacToeGame.AssignCellOwner(1, 1, CellOwners.Computer); ticTacToeGame.AssignCellOwner(2, 0, CellOwners.Computer); // assert ticTacToeGame.CheckForWinner().ShouldBeTrue(); // winner ! ticTacToeGame.Winner.ShouldBe(CellOwners.Computer); ticTacToeGame.IdentifyWinner().ShouldBe("Computer"); }
public void WinnerHuman() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); // act ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 1, CellOwners.Human); ticTacToeGame.AssignCellOwner(2, 2, CellOwners.Human); // assert ticTacToeGame.CheckForWinner().ShouldBeTrue(); // winner ! ticTacToeGame.Winner.ShouldBe(CellOwners.Human); ticTacToeGame.IdentifyWinner().ShouldBe("Unnamed Human"); }
public void IdentifyWinnerHumanTest() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); // act ticTacToeGame.PlayerName = "Prof Reynolds"; ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 1, CellOwners.Human); ticTacToeGame.AssignCellOwner(2, 2, CellOwners.Human); ticTacToeGame.CheckForWinner(); // assert ticTacToeGame.IdentifyWinner().ShouldBe("Prof Reynolds"); }
public void AutoPlayComputerWinnerTest() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); // act ticTacToeGame.AutoPlayComputer(); // 1,1 first good move ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); // 0,2 third in good move list because second good move blocked by human ticTacToeGame.AssignCellOwner(2, 0, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); // 1,0 to block winning move from human ticTacToeGame.AssignCellOwner(1, 0, CellOwners.Human); // this overwrites the previous move by the computer??? ticTacToeGame.AutoPlayComputer(); // 2,2 fifth in good move list // assert ticTacToeGame.CheckForWinner().ShouldBeTrue(); ticTacToeGame.Winner.ShouldBe(CellOwners.Computer); }
public void AutoPlayComputerTest() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); // act ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(2, 2, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(2, 0, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); ticTacToeGame.AssignCellOwner(1, 0, CellOwners.Human); // assert ticTacToeGame.CheckForWinner().ShouldBeTrue(); ticTacToeGame.Winner.ShouldBe(CellOwners.Human); ticTacToeGame.IdentifyWinner().ShouldBe("Human"); }
public void AssignCellOwnerTest() { // make sure that a cell can be assigned as either computer or human // also be sure that only cell within range may be set // many TDD purists argue these are all separate tests // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); // act and assert - assign a cell and check that it is changed ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Human); ticTacToeGame.IdentifyCellOwner(0, 0).ShouldBe(CellOwners.Human); // act and assert - assign a cell as a computer ticTacToeGame.AssignCellOwner(0, 1, CellOwners.Computer); ticTacToeGame.IdentifyCellOwner(0, 1).ShouldBe(CellOwners.Computer); // act and assert - no fault when bad assignment is attempted ticTacToeGame.AssignCellOwner(0, 11, CellOwners.Computer); // should not do anything ticTacToeGame.AssignCellOwner(0, -1, CellOwners.Computer); // should not do anything }
public void AutoPlayComputerWinnerTest() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.ResetGrid(); // act ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); // 0-4 ticTacToeGame.AssignCellOwner(4, 4, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); // 4-0 ticTacToeGame.AssignCellOwner(2, 0, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); // 1-1 ticTacToeGame.AssignCellOwner(2, 1, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); // 1-3 ticTacToeGame.AssignCellOwner(2, 4, CellOwners.Human); ticTacToeGame.AutoPlayComputer(); // 3-1 ticTacToeGame.CheckForWinner(); // 1-3 // assert ticTacToeGame.CheckForWinner().ShouldBeTrue(); ticTacToeGame.Winner.ShouldBe(CellOwners.Computer); }
public void WinnerComputer() { // arrange var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.GridSize = 5; //this code was added so it would test the 5x5 version ticTacToeGame.ResetGrid(); ticTacToeGame.AssignCellOwner(1, 0, CellOwners.Computer); ticTacToeGame.AssignCellOwner(0, 0, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 1, CellOwners.Computer); ticTacToeGame.AssignCellOwner(0, 1, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 2, CellOwners.Computer); ticTacToeGame.AssignCellOwner(0, 2, CellOwners.Human); ticTacToeGame.AssignCellOwner(1, 3, CellOwners.Computer); ticTacToeGame.AssignCellOwner(0, 3, CellOwners.Human); ticTacToeGame.CheckForWinner().ShouldBeFalse(); // no winner --- yet ticTacToeGame.AssignCellOwner(1, 4, CellOwners.Computer); ticTacToeGame.CheckForWinner().ShouldBeTrue(); ticTacToeGame.Winner.ShouldBe(CellOwners.Computer); ticTacToeGame.IdentifyWinner().ShouldBe("Computer"); }