Ejemplo n.º 1
0
  /**
   * Tests that the game starts and stops properly given the number of rounds requested and money
   * available
   */
  @Test
  public void testNumRounds() {
    // test number of rounds played (1 round)
    PlayingStrategy playingStrategy = new PlayingStrategyFixed(Round.Offer.STAND, MONEY_1, false);
    Game game = new Game(playingStrategy, 1, MONEY_10);
    playGameWrapException(game);
    assertEquals(game.getNumRoundsPlayed(), 1);
    assertEquals(game.getNumRoundsToPlay(), 1);
    assertEquals(game.getPastRounds().size(), 1);
    assertEquals(game.isUserInputNeeded(), false);
    assertEquals(game.isFinished(), true);
    assertNull(game.getCurrentRound());
    Round round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);

    // test number of rounds played (5 rounds)
    playingStrategy = new PlayingStrategyFixed(Round.Offer.STAND, MONEY_1, false);
    game = new Game(playingStrategy, 5, MONEY_10);
    playGameWrapException(game);
    assertEquals(game.getNumRoundsPlayed(), 5);
    assertEquals(game.getNumRoundsToPlay(), 5);
    assertEquals(game.getPastRounds().size(), 5);
    assertEquals(game.isUserInputNeeded(), false);
    assertEquals(game.isFinished(), true);
    assertNull(game.getCurrentRound());
    round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);

    // test number of rounds played (money runs out)
    playingStrategy = new PlayingStrategyFixed(Round.Offer.HIT, MONEY_1, false);
    game = new Game(playingStrategy, 20, MONEY_10);
    game.setDeck(
        new MockDeckFixed(
            Rank.TEN)); // by getting only 10s and hitting each time will definitely lose
    playGameWrapException(game);
    assertEquals(game.getNumRoundsPlayed(), 10);
    assertEquals(game.getNumRoundsToPlay(), 20);
    assertEquals(game.getPastRounds().size(), 10);
    assertEquals(game.isUserInputNeeded(), false);
    assertEquals(game.isFinished(), true);
    assertNull(game.getCurrentRound());
    round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);
  }
Ejemplo n.º 2
0
  /** Tests that the interactive strategy properly stops and waits for input and then continues */
  @Test
  public void testGameInteractive() {
    // test number of rounds played (1 round)
    PlayingStrategy playingStrategy = new PlayingStrategyInteractive();
    Game game = new Game(playingStrategy, 1, MONEY_10);
    playGameWrapException(game);
    game.setDeck(
        new MockDeckFixed(
            Rank.TEN)); // deterministic deck needed here; with random may sometimes deal an ACE to
    // dealer, which will cause insurance offer to be made
    assertEquals(game.isFinished(), false);
    assertEquals(game.isUserInputNeeded(), true);
    Round round = game.getCurrentRound();
    assertEquals(Round.RoundStatus.HAND_BEING_DEALT, round.getRoundStatus());

    playingStrategy.setAmountBet(MONEY_1);
    playGameWrapException(game);

    assertEquals(game.isFinished(), false);
    assertEquals(game.isUserInputNeeded(), true);
    round = game.getCurrentRound();
    assertEquals(Round.RoundStatus.HANDS_BEING_PLAYED_OUT, round.getRoundStatus());

    playingStrategy.setResponseToOffer(Offer.STAND);
    playGameWrapException(game);

    assertEquals(game.isFinished(), true);
    assertEquals(game.isUserInputNeeded(), false);
    assertNull(game.getCurrentRound());
    round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);
    assertEquals(game.getNumRoundsPlayed(), 1);
    assertEquals(game.getNumRoundsToPlay(), 1);
    assertEquals(game.getPastRounds().size(), 1);
  }