public void Constructor_Constraints() { var tplayer = new HumanPlayer("jim"); Assert.Throws<ArgumentException>(() => new Game(null, null)); Assert.Throws<ArgumentException>(() => new Game(tplayer, null)); Assert.Throws<ArgumentException>(() => new Game(null, tplayer)); }
public void Constructor_Constraints() { var p1 = new HumanPlayer("jim"); var p2 = new HumanPlayer("tim"); using (var game = new Game(p1, p2)) { Assert.Throws<ArgumentException>(() => new OccupyGameAction(game, p1, 12)); Assert.Throws<ArgumentException>(() => new OccupyGameAction(game, p1, 0, 12,0)); } }
public void Do_ThrowsIfPositionOccupiedAlready() { var p1 = new HumanPlayer("jim"); var p2 = new HumanPlayer("tim"); using (var game = new Game(p1, p2)) { var action = new OccupyGameAction(game, p1, 2, 1); Assert.DoesNotThrow(action.Do); Assert.Throws<InvalidOperationException>(action.Do); } }
public void Constructor_SetsClass() { var p1 = new HumanPlayer("jim"); var p2 = new HumanPlayer("tim"); using (var game = new Game(p1, p2)) { var g = game; var action = A.Fake<GameAction>(x => x.WithArgumentsForConstructor(new object[] { g, p1 })); Assert.AreEqual(p1, action.Player); Assert.AreEqual(game, action.Game); } }
public void Log_FormatsMessage() { var p1 = new HumanPlayer("jim"); var p2 = new HumanPlayer("tim"); using (var game = new Game(p1, p2)) { var g = game; var action = A.Fake<GameAction>(x => x.WithArgumentsForConstructor(new object[] { g, p1 })); action.Log("message {0}", "hi"); Assert.AreEqual("message hi", game.GameLog[0]); } }
public void Do_OccupiesSpaceCorrectly() { var p1 = new HumanPlayer("jim"); var p2 = new HumanPlayer("tim"); using (var game = new Game(p1, p2)) { var action = new OccupyGameAction(game, p1, 2, 1,0); action.Do(); Assert.NotNull(game.Board.BoardPositions[1][2]); Assert.AreEqual(p1, game.Board.BoardPositions[1][2]); } }
public void Do_DoesLog() { var p1 = new HumanPlayer("jim"); var p2 = new HumanPlayer("tim"); using (var game = new Game(p1, p2)) { var action = new OccupyGameAction(game, p1, 2, 1); Assert.AreEqual(0, game.GameLog.Count); action.Do(); Assert.AreEqual(1, game.GameLog.Count); } }
public void Consturctor_SetsClass() { var p1 = new HumanPlayer("jim"); var p2 = new HumanPlayer("tim"); using (var game = new Game(p1, p2)) { var action = new OccupyGameAction(game, p1, 2, 1, 0); Assert.AreEqual(p1, action.Player); Assert.AreEqual(game, action.Game); Assert.AreEqual(2, action.X); Assert.AreEqual(1, action.Y); } }
public void Log_AddsToGameLog() { var p1 = new HumanPlayer("jim"); var p2 = new HumanPlayer("tim"); using (var game = new Game(p1, p2)) { var g = game; var action = A.Fake<GameAction>(x => x.WithArgumentsForConstructor(new object[] { g, p1 })); Assert.AreEqual(0, game.GameLog.Count); action.Log("message"); Assert.AreEqual(1, game.GameLog.Count); } }
public void IsEmpty_Correct() { var p1 = new HumanPlayer("jim"); for (var i = 0; i < 9; i++) { var board = new GameBoard(); Assert.True(board.IsEmpty()); int x, y; board.IndexToCoords(i,out x, out y); board.Occupy(p1,x,y); Assert.False(board.IsEmpty()); } }
public void Constructor_FillsClass() { var h1 = new HumanPlayer("jim"); var h2 = new HumanPlayer("tim"); using (var game = new Game(h1, h2)) { Assert.NotNull(game.Board); Assert.AreEqual(h1, game.Player1); Assert.AreEqual(h2, game.Player2); Assert.NotNull(game.GameLog); Assert.NotNull(game.GameActions); Assert.AreEqual(GameStatus.Running, game.Status); Assert.AreEqual(GameWinStatus.None, game.WinStatus); Assert.Null(game.Winner); Assert.Null(game.PlayerTurn); } }
public void IsFull_IsCorrect() { var board = new GameBoard(); var p1 = new HumanPlayer("jim"); Assert.False(board.IsFull()); board.BoardPositions[0][0] = p1; board.BoardPositions[1][0] = p1; Assert.False(board.IsFull()); board.BoardPositions[2][0] = p1; board.BoardPositions[0][1] = p1; Assert.False(board.IsFull()); board.BoardPositions[1][1] = p1; board.BoardPositions[2][1] = p1; Assert.False(board.IsFull()); board.BoardPositions[0][2] = p1; board.BoardPositions[1][2] = p1; Assert.False(board.IsFull()); board.BoardPositions[2][2] = p1; Assert.True(board.IsFull()); }
public void IsPositionOccupied_IsCorrect() { var board = new GameBoard(); var p1 = new HumanPlayer("jim"); Assert.False(board.IsPositionOccupied(1, 1)); board.Occupy(p1, 1, 1); Assert.True(board.IsPositionOccupied(1, 1)); }
public void ToString_ReturnsName() { var p = new HumanPlayer("jim"); Assert.AreEqual("jim", p.ToString()); }
public void Occupy_SetsBoardPosition() { var board = new GameBoard(); var p1 = new HumanPlayer("jim"); Assert.False(board.BoardPositions[1][1] != null); board.Occupy(p1, 1, 1); Assert.True(board.BoardPositions[1][1] != null); Assert.AreEqual(p1, board.BoardPositions[1][1]); }
public void Winner_IsCorrect() { // ReSharper disable once JoinDeclarationAndInitializer GameBoard board; var p1 = new HumanPlayer("jim"); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][0] = p1; board.BoardPositions[0][1] = p1; board.BoardPositions[0][2] = p1; Assert.AreEqual(p1, board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[1][0] = p1; board.BoardPositions[1][1] = p1; board.BoardPositions[1][2] = p1; Assert.AreEqual(p1, board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[2][0] = p1; board.BoardPositions[2][1] = p1; board.BoardPositions[2][2] = p1; Assert.AreEqual(p1, board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][0] = p1; board.BoardPositions[1][0] = p1; board.BoardPositions[2][0] = p1; Assert.AreEqual(p1, board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][1] = p1; board.BoardPositions[1][1] = p1; board.BoardPositions[2][1] = p1; Assert.AreEqual(p1, board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][2] = p1; board.BoardPositions[1][2] = p1; board.BoardPositions[2][2] = p1; Assert.AreEqual(p1, board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][0] = p1; board.BoardPositions[1][1] = p1; board.BoardPositions[2][2] = p1; Assert.AreEqual(p1, board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][2] = p1; board.BoardPositions[1][1] = p1; board.BoardPositions[2][0] = p1; Assert.AreEqual(p1, board.Winner()); // Make sure doesn't work if one of the spots is occupied by someone else var p2 = new HumanPlayer("tim"); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][0] = p2; board.BoardPositions[0][1] = p1; board.BoardPositions[0][2] = p1; Assert.Null(board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][0] = p1; board.BoardPositions[0][1] = p2; board.BoardPositions[0][2] = p1; Assert.Null(board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][0] = p1; board.BoardPositions[0][1] = p1; board.BoardPositions[0][2] = p2; Assert.Null(board.Winner()); // Make sure doesn't work if one of the spots is not occupied board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][0] = null; board.BoardPositions[0][1] = p1; board.BoardPositions[0][2] = p1; Assert.Null(board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][0] = p1; board.BoardPositions[0][1] = null; board.BoardPositions[0][2] = p1; Assert.Null(board.Winner()); board = new GameBoard(); Assert.Null(board.Winner()); board.BoardPositions[0][0] = p1; board.BoardPositions[0][1] = p1; board.BoardPositions[0][2] = null; Assert.Null(board.Winner()); }
public void Occupy_ThowsIfOccupied() { var board = new GameBoard(); var p1 = new HumanPlayer("jim"); board.Occupy(p1, 1, 1); Assert.Throws<InvalidOperationException>(() => board.Occupy(p1, 1, 1)); }
public void Constructor_FillsClass() { var p = new HumanPlayer("jim"); Assert.AreEqual("jim", p.Name); }
private static Game BasicGame() { var h1 = new HumanPlayer("jim"); var h2 = new HumanPlayer("tim"); var game = new Game(h1, h2); return game; }