123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- package rocks.zipcode;
-
- import org.junit.Assert;
- import org.junit.Test;
-
- public class BlackJackRuleTest {
-
- @Test
- public void testIsBusted_whenPlayerHas21(){
- // Given - set up data
- 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 - invoke method
- boolean actual = rule.isBusted(player);
-
- // Then - verify result
- Assert.assertFalse(actual);
- }
-
- @Test
- public void testIsBusted_whenScoreIsOver21(){
- // Given - set up data
- 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 - invoke method
- boolean actual = rule.isBusted(player);
-
- // Then - verify result
- Assert.assertTrue(actual);
-
- }
-
- @Test
- public void testGetWinner_whenPlayerIsBustedAndDealerIsNot(){
- //Given - setup 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 - invoke method
- Player winner = rule.getWinner(dealer, player);
-
- //Then - verify result
- Assert.assertEquals(dealer, winner);
- }
-
- @Test
- public void testGetWinner_whenPlayerAndDealerAreBusted(){
- //Given - setup 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));
- dealer.addCard(new Cards(Cards.Rank.DEUCE, Cards.Suit.DIAMONDS));
-
- BlackJackRule rule = new BlackJackRule();
-
-
- //When - invoke method
- Player winner = rule.getWinner(dealer, player);
-
- //Then - verify result
- Assert.assertNull(winner);
- }
-
- @Test
- public void testGetWinner_whenPlayerHandIsHigherThanDealer(){
- //Given - setup 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 - invoke method
- Player winner = rule.getWinner(dealer, player);
-
- //Then - verify result
- Assert.assertEquals(player, winner);
- }
-
- @Test
- public void testGetWinner_whenDealerHandIsHigherThanPlayer(){
- //Given - setup 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.ACE, Cards.Suit.DIAMONDS));
-
- BlackJackRule rule = new BlackJackRule();
-
- //When - invoke method
- Player winner = rule.getWinner(dealer, player);
-
- //Then - verify result
- Assert.assertEquals(dealer, winner);
- }
-
- @Test
- public void testGetWinner_whenDealerIsTheSameAsPlayer(){
- //Given - setup 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.JACK, Cards.Suit.DIAMONDS));
-
- BlackJackRule rule = new BlackJackRule();
-
- //When - invoke method
- Player winner = rule.getWinner(dealer, player);
-
- //Then - verify result
- Assert.assertNull(winner);
- }
- }
|