예제 #1
0
  @Test
  public void testHandDouble() {
    PlayingStrategy playingStrategy = new PlayingStrategyFixed(Round.Offer.DOUBLE, MONEY_1, false);
    Game game = new Game(playingStrategy, 1, MONEY_10);
    Deck deck = new MockDeck(Rank.THREE, Rank.TEN, Rank.TEN, Rank.TWO, Rank.EIGHT);
    game.setDeck(deck);
    playGameWrapException(game);
    Round round = game.getLastRound();
    Hand hand = round.getHand(1);
    Hand dealerHand = round.getDealerHand();

    // dealing of cards
    assertEquals(hand, HandTest.toHand(Rank.THREE, Rank.TEN, Rank.TWO));
    assertEquals(dealerHand, HandTest.toHand(Rank.TEN, Rank.EIGHT));

    // calculation of points
    assertEquals(hand.getFinalPoints().intValue(), 15);
    assertEquals(dealerHand.getFinalPoints().intValue(), 18);

    // status changes
    assertEquals(hand.getHandOutcome(), Hand.HandOutcome.LOSS);
    assertEquals(hand.getInsuranceOutcome(), Hand.InsuranceOutcome.NOT_OFFERED);

    // money adjustment
    assertEquals(round.getMoneyStart(), MONEY_10);
    assertEquals(round.getMoneyEnd(), MONEY_8);
    assertEquals(game.getMoneyStart(), MONEY_10);
    assertEquals(game.getMoneyCurrent(), MONEY_8);
  }
예제 #2
0
  @Test
  public void testInsuranceWinGameLose() {
    PlayingStrategy playingStrategy = new PlayingStrategyFixed(Round.Offer.STAND, MONEY_1, true);
    Game game = new Game(playingStrategy, 1, MONEY_10);
    Deck deck = new MockDeck(Rank.THREE, Rank.TEN, Rank.ACE, Rank.JACK);
    game.setDeck(deck);
    playGameWrapException(game);
    Round round = game.getLastRound();
    Hand hand = round.getHand(1);
    Hand dealerHand = round.getDealerHand();

    // dealing of cards
    assertEquals(hand, HandTest.toHand(Rank.THREE, Rank.TEN));
    assertEquals(dealerHand, HandTest.toHand(Rank.ACE, Rank.JACK));

    // calculation of points
    assertEquals(hand.getFinalPoints().intValue(), 13);
    assertEquals(dealerHand.getFinalPoints().intValue(), 21);

    // status changes
    assertEquals(hand.getHandOutcome(), Hand.HandOutcome.LOSS);
    assertEquals(hand.getInsuranceOutcome(), Hand.InsuranceOutcome.WIN);

    // money adjustment
    assertEquals(round.getMoneyStart(), MONEY_10);
    assertEquals(round.getMoneyEnd(), MONEY_10);
    assertEquals(game.getMoneyStart(), MONEY_10);
    assertEquals(game.getMoneyCurrent(), MONEY_10);
  }
예제 #3
0
  @Test
  public void testHandSplit() {
    PlayingStrategy playingStrategy = new PlayingStrategyInteractive();
    Game game = new Game(playingStrategy, 1, MONEY_10);
    Deck deck = new MockDeck(Rank.THREE, Rank.THREE, Rank.TEN, Rank.TWO, Rank.EIGHT, Rank.SEVEN);
    game.setDeck(deck);

    playGameWrapException(game);
    playingStrategy.setAmountBet(MONEY_1);
    playGameWrapException(game);
    playingStrategy.setResponseToOffer(Offer.SPLIT);
    playGameWrapException(game);
    playingStrategy.setResponseToOffer(Offer.STAND);
    playGameWrapException(game);
    playingStrategy.setResponseToOffer(Offer.STAND);

    Round round = game.getLastRound();
    Hand hand1 = round.getHand(1);
    Hand hand2 = round.getHand(2);
    Hand dealerHand = round.getDealerHand();

    // dealing of cards
    assertEquals(hand1, HandTest.toHand(Rank.THREE, Rank.TWO));
    assertEquals(hand2, HandTest.toHand(Rank.THREE, Rank.EIGHT));
    assertEquals(dealerHand, HandTest.toHand(Rank.TEN, Rank.SEVEN));

    // status changes
    assertEquals(hand1.getHandOutcome(), Hand.HandOutcome.LOSS);
    assertEquals(hand2.getHandOutcome(), Hand.HandOutcome.LOSS);

    // money adjustment
    assertEquals(round.getMoneyStart(), MONEY_10);
    assertEquals(round.getMoneyEnd(), MONEY_8);
    assertEquals(game.getMoneyStart(), MONEY_10);
    assertEquals(game.getMoneyCurrent(), MONEY_8);
  }