コード例 #1
0
  public void testThatItTakesFiveForTheHumanPlayerToWin() {
    fakeStrategy.playerSeriesSizes.put(Board.HUMAN_PLAYER_MARK, SERIES_SIZE_OF_FIVE);
    game.updateGameState();

    assertFalse(game.noWinnerYet());
    assertTrue(game.humanPlayerWon());
  }
コード例 #2
0
  // TODO: Declan 17-May-2009 - Updated to test for 6 row in a row rather than 5
  public void testThatItTakesSixForTheComputerToWin() {
    fakeStrategy.playerSeriesSizes.put(Board.COMPUTER_PLAYER_MARK, SERIES_SIZE_OF_SIX);
    game.updateGameState();

    assertFalse(game.noWinnerYet());
    assertTrue(game.computerWon());
  }
コード例 #3
0
  public void testFillGapInPotentialOpposingSeriesOfFour() throws Exception {
    board.setPosition(4, 7, Board.HUMAN_PLAYER_MARK);
    board.setPosition(5, 6, Board.HUMAN_PLAYER_MARK);
    board.setPosition(7, 3, Board.HUMAN_PLAYER_MARK);
    board.setPosition(7, 4, Board.HUMAN_PLAYER_MARK);

    assertEquals(Board.getSingleCoordValueFor(6, 5), game.makeMove());
  }
コード例 #4
0
  public void testWeCanBlockASeriesOfFour() throws Exception {
    board.setPosition(4, 5, Board.HUMAN_PLAYER_MARK);
    board.setPosition(4, 6, Board.HUMAN_PLAYER_MARK);
    board.setPosition(4, 7, Board.HUMAN_PLAYER_MARK);
    board.setPosition(4, 8, Board.HUMAN_PLAYER_MARK);

    assertEquals(Board.getSingleCoordValueFor(4, 9), game.makeMove());
  }
コード例 #5
0
  public void testFindTesseraEndingBlockingPositionBeforePairStartingPosition() throws Exception {
    board.setPosition(2, 3, Board.HUMAN_PLAYER_MARK);
    board.setPosition(3, 2, Board.HUMAN_PLAYER_MARK);
    board.setPosition(3, 3, Board.COMPUTER_PLAYER_MARK);
    board.setPosition(3, 4, Board.COMPUTER_PLAYER_MARK);
    board.setPosition(3, 5, Board.COMPUTER_PLAYER_MARK);
    board.setPosition(3, 6, Board.COMPUTER_PLAYER_MARK);

    assertEquals(Board.getSingleCoordValueFor(3, 7), game.makeMove());
  }
コード例 #6
0
  public void testViewGetsRestartedOnStartNewGame() throws Exception {
    final IGameView mockGameView = mock(IGameView.class);

    checking(
        new Expectations() {
          {
            exactly(2).of(mockGameView).restartGame();
          }
        });
    game = new TicTacToeGame(new ExampleStrategy(), mockGameView);
    game.startNewGame();
  }
コード例 #7
0
  public void testViewUpdatedWithNewMarkOnMove() throws Exception {
    final IGameView mockGameView = mock(IGameView.class);

    checking(
        new Expectations() {
          {
            one(mockGameView).restartGame();

            // Ensure the view gets updated with the one the user selected
            one(mockGameView).drawMark(1, 2, Board.HUMAN_PLAYER_MARK);

            // Allow any choice for the selection of the computer's position
            one(mockGameView)
                .drawMark(
                    with(any(int.class)),
                    with(any(int.class)),
                    with(equal(Board.COMPUTER_PLAYER_MARK)));
          }
        });
    game = new TicTacToeGame(new ExampleStrategy(), mockGameView);
    game.makeCompleteMoveCycle(12);
  }
コード例 #8
0
  public void testThatHumanDoesNotWinWithFourInARow() {
    fakeStrategy.playerSeriesSizes.put(Board.HUMAN_PLAYER_MARK, SERIES_SIZE_OF_FOUR);

    assertTrue("there was a winner when there shouldn't be", game.noWinnerYet());
  }
コード例 #9
0
  // TODO: Declan 17-May-2009 - Updated to test for 5 row in a row rather than 4
  public void testThatComputerDoesNotWinWithFiveInARow() throws Exception {
    fakeStrategy.playerSeriesSizes.put(Board.COMPUTER_PLAYER_MARK, SERIES_SIZE_OF_FIVE);

    assertTrue("there was a winner when there shouldn't be", game.noWinnerYet());
  }
コード例 #10
0
  public void testOnSecondMoveWePickShadowPosition() throws Exception {
    board.setPosition(4, 5, Board.HUMAN_PLAYER_MARK);

    int position = game.makeMove();
    assertEquals(Board.getSingleCoordValueFor(5, 4), position);
  }
コード例 #11
0
  public void testWePickRandomMidBoardSpotForNewGame() throws Exception {
    int position = game.makeMove();

    assertTrue(position < Board.MID_BOARD_UPPER_BOUND);
    assertTrue(position >= Board.MID_BOARD_LOWER_BOUND);
  }
コード例 #12
0
 @Override
 protected void setUp() throws Exception {
   game = new TicTacToeGame(new ExampleStrategy(), new StubView());
   board = game.getBoard();
 }