123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package rocks.zipcode;
-
- import org.junit.Assert;
- import org.junit.Test;
-
- public class BlackJackRuleTest {
-
- @Test
- public void testIsBusted_whenPlayerHas21() {
-
- // setup
- Player player = new Player();
- player.addCard(new Cards(Cards.Rank.ACE, Cards.Suit.CLUBS));
- player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS));
-
- BlackJackRule rule = new BlackJackRule();
-
- // When - invoking method
- boolean actual = rule.isBusted(player);
-
- //Then - verify result
- Assert.assertFalse(actual);
- }
-
- @Test
- public void testIsBusted_whenScoreIsOver21() {
-
- // setup
- Player player = new Player();
-
- player.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.CLUBS));
- player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS));
- player.addCard(new Cards(Cards.Rank.DEUCE, Cards.Suit.CLUBS));
-
-
- BlackJackRule rule = new BlackJackRule();
-
- // When - invoking method
- boolean actual = rule.isBusted(player);
-
- //Then - verify result
- Assert.assertTrue(actual);
- }
-
- @Test
- public void testGetWinner_whenPlayerIsBustedAndDealerIsNot() {
- //Given set up data
- Player player = new Player("Player 1");
-
- player.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.CLUBS));
- player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS));
- player.addCard(new Cards(Cards.Rank.DEUCE, Cards.Suit.CLUBS));
-
- Player dealer = new Player("Dealer");
- dealer.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.DIAMONDS));
- dealer.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.DIAMONDS));
-
- BlackJackRule rule = new BlackJackRule();
-
- // When - invoking method
- Player winner = rule.getWinner(dealer, player);
-
- //Then - verify result
- Assert.assertEquals(winner, dealer);
- }
- @Test
- public void testGetWinner_whenPlayerHandIsHigherThanDealer() {
- //Given set up data
- Player player = new Player("Player 1");
-
- player.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.CLUBS));
- player.addCard(new Cards(Cards.Rank.JACK, Cards.Suit.CLUBS));
-
- Player dealer = new Player("Dealer");
- dealer.addCard(new Cards(Cards.Rank.QUEEN, Cards.Suit.DIAMONDS));
- dealer.addCard(new Cards(Cards.Rank.NINE, Cards.Suit.DIAMONDS));
-
- BlackJackRule rule = new BlackJackRule();
-
- // When - invoking method
- Player winner = rule.getWinner(dealer, player);
-
- //Then - verify result
- Assert.assertEquals(player, winner);
- }
- }
|