diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..5008ddfcf Binary files /dev/null and b/.DS_Store differ diff --git a/Untitled Diagram.xml b/Untitled Diagram.xml new file mode 100644 index 000000000..a0920aa25 --- /dev/null +++ b/Untitled Diagram.xml @@ -0,0 +1 @@ +7Zpdc5s4FIZ/jWe2F97hw2D7svbWrjtp0zrd7uxVRoYDqBaIChHb/fUrgcBgSLfdSQp07ZnE4tVBOjo6PAiZkbkMj2uG4uAtdYGMDM09jsw/Roah68ZcfEnllCv2zM4Fn2FXGZ2FO/wVlKgpNcUuJDVDTinhOK6LDo0icHhNQ4zRQ93Mo6Tea4x8aAh3DiJN9S/s8iBXZ5Z21l8D9oOiZ11TNTvk7H1G00j1NzJML/vk1SEq2lL2SYBceqhI5quRuWSU8rwUHpdAZGyLsOXnrR6pLf1mEPHvOmGKnB2yppMZWObc3o1VCw+IpCoWHkMhKG/5qYiQcDyWxTQkq8zAXBwCzOEuRo7UDyIxhBbwkIgjXRSzqIDsVxNH5cDlgUND7KgyQTsgizKMS0ooE1URjWQfCWd0D4Uooqtln7KmmC3ZoYcJqViqeRA6jfgKhZjI5PwEzEURUrLKRF1Tx20dIYL9SGiOCDGIykUz5kUQgXE4ViQ1B2ugIXB2EiaqdqLSQV0uRXYczrmna6YSg2riabZSkcp4v2z7POuioCa+PQks19Dn1s6daS7ydF0fF5dhJQtGhk1Ep4u4lgb2l1Rm6iJEzMciKC9FrRYfxf8sLlqujzmN87pJpU6Eho9VMGWdimfZpij56jvrGVcEFMrkIs2jjWzDkylYyPVTai2KuODLXnasoRTCGoU7giN/nV0PZRO7yxOEFl9qAZNxKzhXDFF/fLT/Kc4EPF4JdLNtaYtFlgpQAX98yD0fgYOSYBP99uJfPH5eB25T/g0PLmgpSYDF7eWlYkd2QZQkyftcUGHlkQyKEl0XSDIuyfUayAPIVnuK2afA4qzOxYk1b4LRaOOi8SxYtHqIxRI/S5TgiA4YTO8ZFbkEMmmKUhNQ0nAnloKAIlFKE2Cb5AbQg+CyXOghksBAhptwxLi4Dp39Z/FXY8nlgDPTNV3hJOiQepkXS7GuS7p24i1yEO3Iie+7Z175/xT8N7Xp71btDjCbtSyNZ1bLHeApFsabyVfKPjo2uv+gzxzvJtnO/255QurRTaDkyXDvA0PwUfOBf6QckSuEfnkIGdP6ItSetiCo/eHceiYEmX1GUL5OGS5/xHTtV5QtEXO7fMQMwOmBGz5+gI5diLGzfyeSsUM3rrj9ebgtt9L7g9tJn3GbPZANmLb5duQKs4RvqZyLQXgdMxrG/B0cFvCtbcArlH4NKE2s3kGp13uR2QbN4KHkpGFKEBdLoAGR6fpk+r+hkm13SaXPN5/uxtPE+/N2k26Ztd2+ub/v9+bY5nZJo4SSof56O8Cfa3/E5SuQegCkBn1aGPUokKZGfbd+bjaBNG/hUbGp/+Q4MvqMozUDyC2HCCNpWwGqfBXvAq199tyXsX9P0AlYl7trwOXOlnyhqEsvKHUXp648uPL55/HZmhh1Pre9aGhO2haMP05ocXh+jzWrq7wsbL76Bw== \ No newline at end of file diff --git a/pom.xml b/pom.xml index c6ec0cc8b..29f9abbeb 100644 --- a/pom.xml +++ b/pom.xml @@ -2,6 +2,19 @@ + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + 4.0.0 io.zipcoder @@ -15,5 +28,13 @@ 4.12 test + + junit + junit + 4.12 + test + + + diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 000000000..a2eb533ab Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/main/java/io/zipcoder/casino/Casino.java b/src/main/java/io/zipcoder/casino/Casino.java deleted file mode 100644 index 16ca0dd74..000000000 --- a/src/main/java/io/zipcoder/casino/Casino.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.zipcoder.casino; - - -public class Casino { - public static void main(String[] args) { - // write your tests before you start fucking with this - } -} diff --git a/src/main/java/io/zipcoder/casino/casino/Casino.java b/src/main/java/io/zipcoder/casino/casino/Casino.java new file mode 100644 index 000000000..1009274c0 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/Casino.java @@ -0,0 +1,75 @@ +package io.zipcoder.casino.casino; + + +import io.zipcoder.casino.casino.games.Game; + + +public class Casino { + private static Profile profile = new Profile(); + private static Greeter greeter = new Greeter(); + private static boolean userIsLeaving = false; + + public static void main(String[] args) + { + entertainUser(); + } + + static void entertainUser() { + greetUser(); + while (!userIsLeaving) { + Game nextGame = offerUserGames(); + playGameWithUser(nextGame); + offerUserLeave(); + } + seeUserOut(); + } + + static void greetUser() { + String name = greeter.getUserName(); + Boolean gambing = greeter.getIfGambling(name); + profile = new Profile(name, gambing); + } + + static Game offerUserGames() { + Game nextGame; + if(profile.isGambler()) { + nextGame = greeter.getNextGame(); + } else { + nextGame = greeter.getNextCleanGame(); + } + return nextGame; + } + + private static void playGameWithUser(Game nextGame) { + nextGame.play(); + } + + + static void offerUserLeave() { + if(profile.getBalance() > 0) { + userIsLeaving = greeter.getIfLeaving(); + } else { + greeter.balanceTooLow(); + userIsLeaving = true; + } + } + + static void seeUserOut() { + greeter.goodBye(); + } + + public static Profile getProfile() { + return profile; + } + static void setProfile() { + profile = new Profile(); + } + + static void setGreeter(Greeter newGreeter) { + greeter = newGreeter; + } + + static boolean isUserIsLeaving() { + return userIsLeaving; + } +} diff --git a/src/main/java/io/zipcoder/casino/casino/Greeter.java b/src/main/java/io/zipcoder/casino/casino/Greeter.java new file mode 100644 index 000000000..ce45dac48 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/Greeter.java @@ -0,0 +1,194 @@ +package io.zipcoder.casino.casino; + +import io.zipcoder.casino.casino.games.cardgames.BlackJack; +import io.zipcoder.casino.casino.games.cardgames.GoFish; +import io.zipcoder.casino.casino.games.Game; +import io.zipcoder.casino.casino.games.dicegames.Craps; +import io.zipcoder.casino.casino.games.dicegames.Macao; +import io.zipcoder.casino.casino.utilities.Console; + +import java.io.ByteArrayInputStream; +import java.util.NoSuchElementException; +import java.util.Scanner; +import java.util.function.Supplier; + +public class Greeter { + private Console console; + private static final String casinoName = + "\u001b[30;1m __ __ __ __ ______ __ \n" + + "/ \\ / | / | / | / \\ / | \n" + + "$$ \\ $$ |__ __ _____ ____ ______ ______ ______ $$ | $$ |_______ ______ /$$$$$$ | ______ _______$$/ _______ ______ \n" + + "$$$ \\$$ / | / / \\/ \\ / \\ / \\ / \\ $$ | $$ / \\ / \\ $$ | $$/ / \\ / / / \\ / \\ \n" + + "$$$$ $$ $$ | $$ $$$$$$ $$$$ /$$$$$$ /$$$$$$ /$$$$$$ | $$ | $$ $$$$$$$ /$$$$$$ | $$ | $$$$$$ /$$$$$$$/$$ $$$$$$$ /$$$$$$ |\n" + + "$$ $$ $$ $$ | $$ $$ | $$ | $$ $$ $$ $$ | $$/$$ | $$ | $$ | $$ $$ | $$ $$ | $$ | $$ | __ / $$ $$ \\$$ $$ | $$ $$ | $$ |\n" + + "$$ |$$$$ $$ \\__$$ $$ | $$ | $$ $$$$$$$$/$$ | $$ \\__$$ | $$ \\__$$ $$ | $$ $$ \\__$$ | $$ \\__/ /$$$$$$$ |$$$$$$ $$ $$ | $$ $$ \\__$$ |\n" + + "$$ | $$$ $$ $$/$$ | $$ | $$ $$ $$ | $$ $$/ $$ $$/$$ | $$ $$ $$/ $$ $$/$$ $$ / $$/$$ $$ | $$ $$ $$/ \n" + + "$$/ $$/ $$$$$$/ $$/ $$/ $$/ $$$$$$$/$$/ $$$$$$/ $$$$$$/ $$/ $$/ $$$$$$/ $$$$$$/ $$$$$$$/$$$$$$$/ $$/$$/ $$/ $$$$$$/ \n" + + " \u001b[0m"; + private static final String blackJackName = + "\u001b[31m██████╗ ██╗ █████╗ ██████╗██╗ ██╗ ██╗ █████╗ ██████╗██╗ ██╗\n" + + "██╔══██╗██║ ██╔══██╗██╔════╝██║ ██╔╝ ██║██╔══██╗██╔════╝██║ ██╔╝\n" + + "██████╔╝██║ ███████║██║ █████╔╝ ██║███████║██║ █████╔╝ \n" + + "██╔══██╗██║ ██╔══██║██║ ██╔═██╗ ██ ██║██╔══██║██║ ██╔═██╗ \n" + + "██████╔╝███████╗██║ ██║╚██████╗██║ ██╗╚█████╔╝██║ ██║╚██████╗██║ ██╗\n" + + "╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚════╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝\n" + + " \u001b[0m"; + private static final String goFishName = + "\u001b[32;1m ██████╗ ██████╗ ███████╗██╗███████╗██╗ ██╗\n" + + "██╔════╝ ██╔═══██╗██╔════╝██║██╔════╝██║ ██║\n" + + "██║ ███╗██║ ██║█████╗ ██║███████╗███████║\n" + + "██║ ██║██║ ██║██╔══╝ ██║╚════██║██╔══██║\n" + + "╚██████╔╝╚██████╔╝██║ ██║███████║██║ ██║\n" + + " ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝\n" + + " \u001b[0m"; + private static final String crapsName = + "\u001b[35m ██████╗██████╗ █████╗ ██████╗ ███████╗\n" + + "██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝\n" + + "██║ ██████╔╝███████║██████╔╝███████╗\n" + + "██║ ██╔══██╗██╔══██║██╔═══╝ ╚════██║\n" + + "╚██████╗██║ ██║██║ ██║██║ ███████║\n" + + " ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══════╝\n" + + " \u001b[0m"; + private static final String macaoName = + "\u001b[34;1m███╗ ███╗ █████╗ ██████╗ █████╗ ██████╗ \n" + + "████╗ ████║██╔══██╗██╔════╝██╔══██╗██╔═══██╗\n" + + "██╔████╔██║███████║██║ ███████║██║ ██║\n" + + "██║╚██╔╝██║██╔══██║██║ ██╔══██║██║ ██║\n" + + "██║ ╚═╝ ██║██║ ██║╚██████╗██║ ██║╚██████╔╝\n" + + "╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ \u001b[0m"; + + public static String getBlackJackName() { + return blackJackName; + } + + public static String getGoFishName() { + return goFishName; + } + + public static String getCrapsName() { + return crapsName; + } + + public static String getMacaoName() { + return macaoName; + } + + Greeter(){ + this.console = Console.getConsole(); + } + + Greeter(Console console) { + this.console = console; + } + + String getUserName() { + try { + console.println(casinoName); + return console.getStringInput("Welcome to our casino! What's your name?"); + } catch (NoSuchElementException exception) { + return "Jane Doe"; + } + } + + Boolean getIfGambling(String name) { + Integer age = console.getIntegerInput(String.format("It's great to meet you, %s. How old are you?", name)); + if (age >= 18) { + String isGambling = console.getStringInput("And will you be gambling here today?"); + return parseIsGambling(isGambling); + } else { + console.print("No problem, we're happy to offer GoFish and Macao for our nongamblers. They do still" + + " cost money, though. Your starting balance is \u20A6500 NUC Bucks.\n"); + return false; + } + } + + private Boolean parseIsGambling(String isGambling) { + isGambling = isGambling.toLowerCase().trim(); + if ("yes".equals(isGambling)) { + console.println("Your starting balance with us is \u20A6500 NUC Bucks. Best of luck!"); + return true; + } else if ("no".equals(isGambling)) { + console.println("Okay, but our non-gambling games do still cost money to play. You have \u20A6500 NUC Bucks to start."); + return false; + } else { + console.println("That sounds like a yes!"); + return true; + } + } + + Game getNextGame() { + String requestedGame = console.getStandardInputCaps( + "Would you like to play BlackJack, GoFish, Craps or Macao?"); + return parseGame(requestedGame); + } + + Game getNextCleanGame() { + String requestedGame = console.getStandardInputCaps("Would you like to play GoFish or Macao?"); + if (requestedGame.equals("BLACKJACK") || requestedGame.equals("CRAPS")) {requestedGame = "GOFISH";} + return parseGame(requestedGame); + } + + private Game parseGame(String requestedGame) { + if (requestedGame.equals("TESTINGCHEATSENABLEDTRUE")) {return getCheatingTest();} + GameEnum enumeration = GameEnum.getValueOf(requestedGame); + return enumeration.create(); + } + + + + public enum GameEnum { + BLACKJACK(BlackJack::new), + CRAPS(Craps::new), + GOFISH(GoFish::new), + MACAO(Macao::new); + + private final Supplier supplier; + + GameEnum(Supplier supplier) { + this.supplier = supplier; + } + + public Game create() { + return this.supplier.get(); + } + + public static io.zipcoder.casino.casino.Greeter.GameEnum getValueOf(String userInput) { + try { + return valueOf(userInput); + } catch (IllegalArgumentException var2) { + return valueOf("GOFISH"); + } + } + } + + private Game getCheatingTest() { + String input = "yes\nno"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + return new Macao(console); + } + + boolean getIfLeaving() { + String isLeaving = console.getStringInput("\n\n\nGood Game. Would you like to stay in our casino?"); + if (isLeaving.equals("no") || isLeaving.equals("n")) { + return true; + } else if (isLeaving.toLowerCase().trim().equals("yes")) { + console.println("We're happy you're staying!"); + return false; + } else { + console.println("It sounds like you'd like to play another game!"); + return false; + } + } + + void balanceTooLow() { + console.println("Sorry, your balance is too low to keep playing."); + } + + void goodBye() { + console.println(casinoName); + console.println("Thank you so much for coming! Please come again!"); + } + +} diff --git a/src/main/java/io/zipcoder/casino/casino/Player.java b/src/main/java/io/zipcoder/casino/casino/Player.java new file mode 100644 index 000000000..3412890aa --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/Player.java @@ -0,0 +1,17 @@ +package io.zipcoder.casino.casino; + + +public abstract class Player { + private Profile profile; + public Player(Profile profile) { + + this.profile = profile; + } + public Player() { + profile = new Profile(); + } + + public Profile getProfile() { + return this.profile; + } +} diff --git a/src/main/java/io/zipcoder/casino/casino/Profile.java b/src/main/java/io/zipcoder/casino/casino/Profile.java new file mode 100644 index 000000000..60247d970 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/Profile.java @@ -0,0 +1,35 @@ +package io.zipcoder.casino.casino; + +public class Profile { + private String name; + private boolean gambler; + private Integer balance; + + public Profile(String name, boolean canGamble) { + this.name = name; + this.gambler = canGamble; + this.balance = 500; + } + + public Profile() { + this.name = "Dealer"; + this.gambler = true; + this.balance = 5000000; + } + + public String getName() { + return name; + } + + public boolean isGambler() { + return gambler; + } + + public Integer getBalance() { + return balance; + } + + public void setBalance(Integer balance) { + this.balance = balance; + } +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/Game.java b/src/main/java/io/zipcoder/casino/casino/games/Game.java new file mode 100644 index 000000000..29619e337 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/Game.java @@ -0,0 +1,5 @@ +package io.zipcoder.casino.casino.games; + +public interface Game { + void play(); +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/cardgames/BlackJack.java b/src/main/java/io/zipcoder/casino/casino/games/cardgames/BlackJack.java new file mode 100644 index 000000000..fa843e649 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/cardgames/BlackJack.java @@ -0,0 +1,272 @@ +package io.zipcoder.casino.casino.games.cardgames; + + +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Card; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Deck; +import io.zipcoder.casino.casino.Casino; +import io.zipcoder.casino.casino.Greeter; +import io.zipcoder.casino.casino.games.Game; +import io.zipcoder.casino.casino.Profile; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Rank; +import io.zipcoder.casino.casino.utilities.Console; + + +import java.util.ArrayList; +import java.util.List; + + +public class BlackJack implements Game { + + private BlackJackPlayer dealer = new BlackJackPlayer(new Profile()); + private BlackJackPlayer user = new BlackJackPlayer(Casino.getProfile()); + private Deck currentDeck = new Deck(); + private int userTotal; + private int dealerTotal; + private Integer userBet; + private boolean isOver = false; + private Console blackJackConsole; + + public BlackJack(){ + this(Console.getConsole()); + } + + public BlackJack(Console testConsole) { + blackJackConsole = testConsole; + } + + public BlackJackPlayer getUser(){ + return this.user; + } + public BlackJackPlayer getDealer(){ + return this.dealer; + } + + public Integer getUserBetAsInteger(){ + return userBet; + } + public void setUserTotal(int total){ + this.userTotal = total; + } + public void setDealerTotal(int total) {this.dealerTotal = total;} + public void setUserBet(Integer userBet) { + this.userBet = userBet; + } + + + public void play() { + blackJackConsole.println(Greeter.getBlackJackName()); + getUserBet(); + playFirstTurn(); + + while (!isOver) { + evaluateUserHitOrStay(); + } + } + + public void getUserBet() { + blackJackConsole.println("Your current balance is $" + user.getBalance()); + userBet = blackJackConsole.getIntegerInput("Place a bet if you DARE"); + + while(userBet > user.getBalance()){ + tellUserDeyPoor(); + userBet = blackJackConsole.getIntegerInput("Place a bet if you DARE"); + } + decreaseBalance(); + } + + public void tellUserDeyPoor(){ + blackJackConsole.println("Your broke ass has insufficient funds.."); + } + + + private void playFirstTurn() { + dealFirstHand(); + blackJackConsole.print(Card.printAllCards(user.getHand())); + displayUserTotal(userTotal); + isOver = (userTotal == 21); + if(isOver){ + celebrateUser(); + } else { + displayDealersFirstHand(); + checkIfUserWantsToDoubleDown(); + } + } + + public void dealFirstHand(){ + user.setHand(currentDeck.drawMultipleCards(2)); + dealer.setHand(currentDeck.drawMultipleCards(2)); + userTotal = getTotal(user.getHand()); + dealerTotal = getTotal(dealer.getHand()); + } + + public void displayDealersFirstHand(){ + List printingCards = new ArrayList<>(); + blackJackConsole.println("Dealer's hand is showing: "); + printingCards.add(dealer.getHand().get(0)); + printingCards.add(Deck.getCardBack()); + blackJackConsole.println(Card.printAllCards(printingCards)); + } + + public void checkIfUserWantsToDoubleDown(){ + String doubleDownChoice = blackJackConsole.getStringInput( + "Would you like to Double Down? Please enter Yes or No"); + while(!doubleDownChoice.toLowerCase().equals("yes") && !doubleDownChoice.toLowerCase().equals("no") ){ + blackJackConsole.println("Please enter a valid option of Yes or No"); + doubleDownChoice = blackJackConsole.getStringInput( + "Would you like to Double Down? Please enter Yes or No"); + } + if (doubleDownChoice.toLowerCase().equals("yes") && userBet <= user.getBalance()) { + doubleDown(); + } else if (doubleDownChoice.toLowerCase().equals("yes") && userBet > user.getBalance()){ + tellUserDeyPoor(); + } + } + + public void evaluateUserHitOrStay() { + + String userChoice = getUserInput().toLowerCase(); + if(!userChoice.equals("hit") && !userChoice.equals("stay") ){ + blackJackConsole.println("Please enter a valid option of Hit or Stay"); + } + else if (userChoice.equals("hit")) { + hit(); + checkGameOverByBust(); + isOver = (userTotal == 21); + } else { + takeDealersTurn(); + } + } + + private void doubleDown() { + decreaseBalance(); + userBet = userBet * 2; + + blackJackConsole.println("Bet is now $" + userBet); + + user.getHand().add(currentDeck.drawCard()); + userTotal = getTotal(user.getHand()); + + blackJackConsole.print("Your next card is \n" + Card.printAllCards(user.getHand().get(2))); + + displayUserTotal(userTotal); + checkGameOverByBust(); + + if (!isOver) { + isOver = (userTotal == 21); + takeDealersTurn(); + } + } + + public void hit() { + user.getHand().add(currentDeck.drawCard()); + userTotal = getTotal(user.getHand()); + blackJackConsole.println("Your next card is \n" + Card.printAllCards(user.getHand().get(user.getHand().size()-1)) + + "Your total hand is " + userTotal); + } + + public String getUserInput() { + + String userChoice = blackJackConsole.getStringInput("Would you like to Hit or Stay?"); + return userChoice; + } + + public int getTotal(List hand) { + int sum = 0; + int acesCounter = 0; + + for (Card card : hand) { + if(card.getRank() == Rank.ACE){ + acesCounter++; + } + sum += card.getRank().returnPrimaryRankValue(); + while(sum > 21 && acesCounter>0){ + sum -= 10; + acesCounter--; + } + } + return sum; + } + + + public void displayUserTotal(int userTotal) { + blackJackConsole.println("Your total is " + userTotal); + } + + public void displayDealerTotal(int dealerTotal) { + blackJackConsole.println("Dealer total is " + dealerTotal); + } + + public void displayUserBalance(){ + blackJackConsole.println("Your balance is: $" + user.getBalance()); + } + + public void displayDealerHand() { + blackJackConsole.println("Dealer's hand is now: \n" + Card.printAllCards(dealer.getHand())); + } + + public boolean checkGameOverByBust() { + if (userTotal > 21) { + blackJackConsole.println("You Bust. Dealer wins!"); + displayUserBalance(); + isOver = true; + } + return isOver; + } + + + public void celebrateUser(){ + blackJackConsole.println("You are the Winner!!!!"); + addWinningsBalance(); + displayUserBalance(); + + } + + private void takeDealersTurn() { + blackJackConsole.println("Dealer card is: \n" + Card.printAllCards(dealer.getHand().get(1))); + displayDealerHand(); + displayDealerTotal(dealerTotal); + while (dealerTotal < 17) { + dealer.getHand().add(currentDeck.drawCard()); + blackJackConsole.println("The dealer drew \n" + Card.printAllCards(dealer.getHand().get(dealer.getHand().size() - 1))); + dealerTotal = getTotal(dealer.getHand()); + displayDealerHand(); + displayDealerTotal(dealerTotal); + } + checkWinner(); + } + + public void checkWinner() { + if (dealerTotal > 21) { + blackJackConsole.print("Dealer Busts."); + celebrateUser(); + isOver = true; + + } else if (dealerTotal == userTotal) { + blackJackConsole.println("It's a Push. Ehh"); + user.setBalance(user.getBalance() + userBet); + displayUserBalance(); + isOver = true; + } else { + String result = (dealerTotal > userTotal) ? "Dealer is the winner!" : "You are the winner" ; + if (result.equals("You are the winner")){ + addWinningsBalance(); + } + blackJackConsole.println(result); + displayUserBalance(); + isOver = true; + } + } + + private void addWinningsBalance() { + user.setBalance(user.getBalance() + (userBet * 2)); + } + + private void decreaseBalance() { + user.setBalance(user.getBalance() - userBet); + displayUserBalance(); + } + } + + + + diff --git a/src/main/java/io/zipcoder/casino/casino/games/cardgames/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/casino/games/cardgames/BlackJackPlayer.java new file mode 100644 index 000000000..e12fc0b67 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/cardgames/BlackJackPlayer.java @@ -0,0 +1,36 @@ +package io.zipcoder.casino.casino.games.cardgames; + +import io.zipcoder.casino.casino.Player; +import io.zipcoder.casino.casino.Profile; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Card; + +import java.util.List; + +public class BlackJackPlayer extends Player { + + public BlackJackPlayer(Profile profile){ + super(profile); + } + + private List hand; + + public List getHand() { + return hand; + } + + public void setHand(List hand) { + + this.hand = hand; + } + + public Profile getProfile(){ + return super.getProfile(); + } + + public int getBalance(){ + return getProfile().getBalance(); + } + public void setBalance(int newBalance){ + getProfile().setBalance(newBalance); + } +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/cardgames/GoFish.java b/src/main/java/io/zipcoder/casino/casino/games/cardgames/GoFish.java new file mode 100644 index 000000000..559b9fb55 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/cardgames/GoFish.java @@ -0,0 +1,229 @@ +package io.zipcoder.casino.casino.games.cardgames; + +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Card; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Deck; +import io.zipcoder.casino.casino.Casino; +import io.zipcoder.casino.casino.Greeter; +import io.zipcoder.casino.casino.games.Game; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Rank; +import io.zipcoder.casino.casino.utilities.Console; + + +import java.util.HashMap; +import java.util.List; +import java.util.Set; + +public class GoFish implements Game { + private GoFishPlayer dealer = new GoFishPlayer(); + private GoFishPlayer user = new GoFishPlayer(Casino.getProfile()); + private Deck deck = new Deck(); + private boolean isOver = false; + private Console console; + + public boolean isOver() { + return isOver; + } + + public void setIsOver(boolean isOver) { this.isOver = isOver; } + public Deck getDeck() { return deck; } + + public GoFishPlayer getDealer() { + return dealer; + } + public GoFishPlayer getUser() { + return user; + } + + public GoFish(Console console) { + this.console = console; + } + public GoFish() { + console = Console.getConsole(); + } + + public void play() { + console.println(Greeter.getGoFishName()); + user.getProfile().setBalance(user.getProfile().getBalance() - 5); + console.println("Rules: The object of this game is to get the most books (4 of a kind) down.\nHere's your staring hand:\n"); + dealStartingHands(); + while (!isOver) { + displayStatus(); + dealerTurn(); + evaluate(); + displayStatus(); + userTurn(); + evaluate(); + } + } + + public void dealerTurn() { + if(dealer.getHandSize() != 0) { + tryForUserCard(); + } else { + console.println("I'm out of cards in my hand! I'll just draw"); + goFish(dealer); + } + playBooks(); + } + + public void playBooks() { + if (dealer.hasBooks()) { + List books = dealer.getBooks(); + console.println("Alright, I'm going to play these:"); + console.println(Card.printAllCards(books)); + } + } + + public void tryForUserCard() { + String askedFor = dealer.getRandomCard().getRank().toString(); + boolean saysHasCard = askForCard(askedFor); + if (user.hasCard(askedFor)) { + if (!saysHasCard) { console.println("J'accuse!");} + takeCards(askedFor); + } else if (saysHasCard) { + console.println("Huh, it doesn't actually look like you do."); + goFish(dealer); + } else { + goFish(dealer); + } + } + + private boolean askForCard(String askedFor) { + String hasCard = console.getStandardInput(String.format("Do you have any %ss?", askedFor)); + return hasCard.equals("yes"); + } + + private void takeCards(String askedFor) { + List takenCards = user.getCards(askedFor); + console.println("I'll take these:"); + console.print(Card.printAllCards(takenCards)); + dealer.addToHand(takenCards); + } + + private void dealStartingHands() { + dealer.setHand(deck.drawMultipleCards(5)); + user.setHand(deck.drawMultipleCards(5)); + } + + public void userTurn() { + String askedForCard = console.getStandardInputCaps("What card would you like to ask for?"); + if(!user.hasCard(askedForCard)) { + console.println("You can only ask for cards you have"); + userTurn(); + } else { + boolean hasCard = dealer.hasCard(askedForCard); + dealerResponse(hasCard, askedForCard); + if (user.hasBooks()) { + bookTurn(); + } + } + } + + private void dealerResponse(boolean hasCard, String askedForCard) { + if (hasCard) { + List givenCards = dealer.getCards(askedForCard); + user.addToHand(givenCards); + console.println(String.format("You got me! Here's %d %ss", givenCards.size(), askedForCard)); + userTurn(); + } else { + goFish(user, askedForCard); + } + } + + public void bookTurn() { + boolean playingBook = playBook(); + if(playingBook) { + displayStatus(); + List playedBooks = getPotentialBook(); + if(playedBooks.size() != 4) { + console.println("That's not a book."); + user.addToHand(playedBooks); + bookTurn(); + } else if (user.hasBooks()) { + bookTurn(); + } + } + } + + private List getPotentialBook() { + user.increaseBookCount(); + String playBooks = console.getStandardInputCaps(String.format("What type of card do you want to play? (%s)", getAllBooks())); + return user.getCards(playBooks); + } + + private String getAllBooks() { + HashMap rankCount = new HashMap<>(); + for (Card card : user.getHand()) { + Rank rank = card.getRank(); + if(rankCount.get(rank) == null) { + rankCount.put(rank, 0); + } else { + rankCount.put(rank, rankCount.get(rank) + 1); + } + } + return allBooksString(rankCount); + } + + private String allBooksString(HashMap rankCount) { + StringBuilder allBooks = new StringBuilder(); + Set allRanks = rankCount.keySet(); + for (Rank rank : allRanks) { + if(rankCount.get(rank) > 2) { + allBooks.append(rank + " "); + } + } + return allBooks.toString(); + } + + private void goFish(GoFishPlayer player) { + if(deck.cardsLeft() != 0) { + Card card = deck.drawCard(); + player.addToHand(card); + } else { + console.println("There are no more cards in the deck"); + } + } + + public void goFish(GoFishPlayer player, String askedFor) { + if(deck.cardsLeft() != 0) { + console.println("Nope! Go Fish!"); + Card card = deck.drawCard(); + player.addToHand(card); + if(card.getRank().equals(GoFishPlayer.parseCardString(askedFor))) { + console.println("Fish, Fish, you got your wish!"); + } + console.println(String.format("YOU DREW:\n%s", card.printCard())); + } else { + console.println("There are no more cards in the deck"); + } + } + + public void displayStatus() { + console.print(Card.printAllCards(user.getHand())); + console.println(String.format("YOU: %d DEALER: %d", + user.getBookCount(), dealer.getBookCount())); + } + + + private boolean playBook() { + String playbook = console.getStandardInput("Would you like to play a book?"); + if ("yes".equals(playbook) || "y".equals(playbook)) { + return true; + } else { + console.println("Okay, we'll keep going"); + return false; + } + } + + public void evaluate() { + if(dealer.getBookCount() + user.getBookCount() == 13) { + isOver = true; + if (user.getBookCount() > dealer.getBookCount()) { + console.println("You won! Great game."); + } else if (user.getBookCount() < dealer.getBookCount()) { + console.println("Looks like I beat you this time. Come back anytime!"); + } + } + } + +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/cardgames/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/casino/games/cardgames/GoFishPlayer.java new file mode 100644 index 000000000..e73814f52 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/cardgames/GoFishPlayer.java @@ -0,0 +1,132 @@ +package io.zipcoder.casino.casino.games.cardgames; + +import io.zipcoder.casino.casino.Player; +import io.zipcoder.casino.casino.Profile; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Card; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Rank; + +import java.util.*; + +public class GoFishPlayer extends Player { + public GoFishPlayer() { + super(); + } + public GoFishPlayer(Profile profile) { + super(profile); + } + private List hand = new ArrayList<>(); + private int bookCount = 0; + + public List getHand() { + return hand; + } + public void setHand(List hand) { if(hand != null) { this.hand = hand; Collections.sort(this.hand);} } + public int getHandSize(){ return hand.size(); } + + public void addToHand(List cards) {if(hand != null) {this.hand.addAll(cards); Collections.sort(hand);} } + public void addToHand(Card card) {if(hand != null) {this.hand.add(card); Collections.sort(hand);} } + public int getBookCount() { + return bookCount; + } + public void increaseBookCount() { + bookCount++; + } + + public boolean hasCard(String checkCard) { + Rank cardRank = parseCardString(checkCard); + if (cardRank == null){ return false; } + for (Card card : hand) { + if(card.getRank().equals(cardRank)) { + return true; + } + } + return false; + } + + + public List getCards(String getCard) { + Rank cardRank = parseCardString(getCard); + List retrievedCards = new ArrayList<>(); + for (Card card : hand) { + if(card.getRank().equals(cardRank)) { + retrievedCards.add(card); + } + } + hand.removeAll(retrievedCards); + return retrievedCards; + } + + public Card getRandomCard() { + Collections.shuffle(hand); + return hand.get(0); + } + + public boolean hasBooks() { + if(hand.size() < 4) { return false;} + for (int i = 0; i < hand.size()-3; i++) { + List nextFour = getNextFour(i); + if(Card.equalRank(nextFour)) { + return true; + } + } + return false; + } + + public List getBooks() { + List cardBooks = new ArrayList<>(); + for (int i = 0; i < hand.size() - 3; i++) { + List nextFour = getNextFour(i); + if (Card.equalRank(nextFour)) { + cardBooks.addAll(nextFour); + i+=3; + bookCount++; + } + } + hand.removeAll(cardBooks); + return cardBooks; + } + + private List getNextFour(int i) { + List nextFour = new ArrayList<>(); + nextFour.add(hand.get(i)); + nextFour.add(hand.get(i+1)); + nextFour.add(hand.get(i+2)); + nextFour.add(hand.get(i+3)); + return nextFour; + } + + public static Rank parseCardString(String checkCard) { + return possibleUserInputs.get(checkCard.toLowerCase()); + } + + private static final HashMap possibleUserInputs = new HashMap<>(); + static { + possibleUserInputs.put("king", Rank.KING); possibleUserInputs.put("kings", Rank.KING); + possibleUserInputs.put("k", Rank.KING); possibleUserInputs.put("ks", Rank.KING); + possibleUserInputs.put("queen", Rank.QUEEN); possibleUserInputs.put("queens", Rank.QUEEN); + possibleUserInputs.put("q", Rank.QUEEN); possibleUserInputs.put("qs", Rank.QUEEN); + possibleUserInputs.put("jack", Rank.JACK); possibleUserInputs.put("jacks", Rank.JACK); + possibleUserInputs.put("j", Rank.JACK); possibleUserInputs.put("js", Rank.JACK); + possibleUserInputs.put("ace", Rank.ACE); possibleUserInputs.put("aces", Rank.ACE); + possibleUserInputs.put("a", Rank.ACE); possibleUserInputs.put("as", Rank.ACE); + possibleUserInputs.put("ten", Rank.TEN); possibleUserInputs.put("tens", Rank.TEN); + possibleUserInputs.put("10", Rank.TEN); possibleUserInputs.put("10s", Rank.TEN); + possibleUserInputs.put("nine", Rank.NINE); possibleUserInputs.put("nines", Rank.NINE); + possibleUserInputs.put("9", Rank.NINE); possibleUserInputs.put("9s", Rank.NINE); + possibleUserInputs.put("eight", Rank.EIGHT); possibleUserInputs.put("eights", Rank.EIGHT); + possibleUserInputs.put("8", Rank.EIGHT); possibleUserInputs.put("8s", Rank.EIGHT); + possibleUserInputs.put("seven", Rank.SEVEN); possibleUserInputs.put("sevens", Rank.SEVEN); + possibleUserInputs.put("7", Rank.SEVEN); possibleUserInputs.put("7s", Rank.SEVEN); + possibleUserInputs.put("six", Rank.SIX); possibleUserInputs.put("sixes", Rank.SIX); + possibleUserInputs.put("6", Rank.SIX); possibleUserInputs.put("6s", Rank.SIX); + possibleUserInputs.put("five", Rank.FIVE); possibleUserInputs.put("fives", Rank.FIVE); + possibleUserInputs.put("5", Rank.FIVE); possibleUserInputs.put("5s", Rank.FIVE); + possibleUserInputs.put("four", Rank.FOUR); possibleUserInputs.put("fours", Rank.FOUR); + possibleUserInputs.put("4", Rank.FOUR); possibleUserInputs.put("4s", Rank.FOUR); + possibleUserInputs.put("three", Rank.THREE); possibleUserInputs.put("threes", Rank.THREE); + possibleUserInputs.put("3", Rank.THREE); possibleUserInputs.put("3s", Rank.THREE); + possibleUserInputs.put("two", Rank.TWO); possibleUserInputs.put("twos", Rank.TWO); + possibleUserInputs.put("2", Rank.TWO); possibleUserInputs.put("2s", Rank.TWO); + } + +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Card.java b/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Card.java new file mode 100644 index 000000000..b7543dc09 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Card.java @@ -0,0 +1,93 @@ +package io.zipcoder.casino.casino.games.cardgames.cardutilities; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Card implements Comparable{ + + private Suit suit; + private Rank rank; + public Card(Suit suit, Rank rank) { + this.suit = suit; + this.rank = rank; + } + + public Suit getSuit() { + return suit; + } + + public Rank getRank() { + return rank; + } + + public String toString() { + return rank.toString().toLowerCase() + " of " + suit.toString().toLowerCase(); + } + + public String printCard() { + String top = rank.getStringRepresentation(); + String bottom = rank.getStringRepresentation(); + //Add on lines to non-10 ranks to make all the cards evenly sized. + if (!rank.equals(Rank.TEN)) { + top += "\u2501"; + bottom = "\u2501" + bottom; + } + String fullCard = String.format("%s\u2501\u2501\u2513\n\u2503 \u2503\n\u2503 %s \u2503\n\u2503 \u2503\n\u2517\u2501\u2501%s", + top, suit.getStringRepresentation(), bottom); + return fullCard; + } + + public static String printAllCards(Card... cards) { + return printAllCards(new ArrayList<>(Arrays.asList(cards))); + } + + + public static String printAllCards(List cards) { + StringBuilder allCardsPrinted = new StringBuilder(); + for (int i = 0; i < 5; i++) { + for (Card card : cards) { + if(card.getSuit() != null) { + allCardsPrinted.append(card.splitCard()[i]); + } else { + allCardsPrinted.append(printCardBack()[i]); + } + } + allCardsPrinted.append("\n"); + } + return allCardsPrinted.toString(); + } + private String[] splitCard() { + return printCard().split("\n"); + } + + private static String[] printCardBack() { + return new String[]{"\u250F\u2501\u2501\u2501\u2513", "\u2503\u0220 \u2503", "\u2503 \u0244 \u2503", + "\u2503 \u0297\u2503", "\u2517\u2501\u2501\u2501\u251B"}; + } + + + public int compareTo(Card otherCard) { + int rankCompare = otherCard.getRank().compareTo(rank) * 2; + int suiteCompare = 0; + if (rankCompare == 0) { + suiteCompare = otherCard.getSuit().compareTo(suit); + } + return rankCompare + suiteCompare; + } + + public boolean equalRank(Card otherCard) { + return otherCard.getRank().toString().equals(rank.toString()); + } + public static boolean equalRank(List otherCards) { + for (int i = 0; i < otherCards.size() - 1; i++) { + String currentRank = otherCards.get(i).getRank().toString(); + String nextRank = otherCards.get(i+1).getRank().toString(); + if(!currentRank.equals(nextRank)) { + return false; + } + } + return true; + } + +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Deck.java b/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Deck.java new file mode 100644 index 000000000..d0405aa08 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Deck.java @@ -0,0 +1,50 @@ +package io.zipcoder.casino.casino.games.cardgames.cardutilities; + + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + + +public class Deck { + private final static List COMPLETE_DECK = new ArrayList(); + private final static Card cardBack = new Card(null, null); + private Stack playDeck; + + static { + for (Suit suit : Suit.values()) { + for (Rank rank : Rank.values()) { + COMPLETE_DECK.add(new Card(suit, rank)); + } + } + } + + public static Card getCardBack() { + return cardBack; + } + + public Deck() { + playDeck = new Stack<>(); + playDeck.addAll(COMPLETE_DECK); + Collections.shuffle(playDeck); + + } + + public List drawMultipleCards(int numberOfCards) { + List newCards = new ArrayList(); + for (int i = 0; i < numberOfCards; i++) { + newCards.add(playDeck.pop()); + } + return newCards; + } + + public Card drawCard() { + return playDeck.pop(); + } + public int cardsLeft() { return playDeck.size(); } + + public Stack getPlayDeck() { + return playDeck; + } +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Rank.java b/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Rank.java new file mode 100644 index 000000000..980e28b89 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Rank.java @@ -0,0 +1,45 @@ +package io.zipcoder.casino.casino.games.cardgames.cardutilities; + +public enum Rank { + + ACE(11, "A"), + + TWO(2, "2"), + + THREE(3, "3"), + + FOUR(4, "4"), + + FIVE(5, "5"), + + SIX(6, "6"), + + SEVEN(7, "7"), + + EIGHT(8, "8"), + + NINE(9, "9"), + + TEN(10, "10"), + + JACK(10, "J"), + + QUEEN(10, "Q"), + + KING(10, "K"); + + private int value; + private String stringRepresentation; + + Rank(int value, String stringRepresentation) { + this.value = value; + this.stringRepresentation = stringRepresentation; + } + + public int returnPrimaryRankValue() { + return this.value; + } + + public String getStringRepresentation() { + return this.stringRepresentation; } +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Suit.java b/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Suit.java new file mode 100644 index 000000000..f3f8aeb76 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/cardgames/cardutilities/Suit.java @@ -0,0 +1,16 @@ +package io.zipcoder.casino.casino.games.cardgames.cardutilities; + +public enum Suit { + SPADES( "\u2664" ), + HEARTS( "\u2661" ), + DIAMONDS( "\u2662" ), + CLUBS( "\u2667" ); + + private String stringRepresentation; + + Suit(String stringRepresentation) { + this.stringRepresentation = stringRepresentation; + } + + public String getStringRepresentation() { return this.stringRepresentation; } +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/dicegames/Craps.java b/src/main/java/io/zipcoder/casino/casino/games/dicegames/Craps.java new file mode 100644 index 000000000..7b1c2ca0f --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/dicegames/Craps.java @@ -0,0 +1,492 @@ +package io.zipcoder.casino.casino.games.dicegames; + +import io.zipcoder.casino.casino.games.dicegames.diceutilities.Dice; +import io.zipcoder.casino.casino.games.Game; +import io.zipcoder.casino.casino.Casino; +import io.zipcoder.casino.casino.Greeter; +import io.zipcoder.casino.casino.utilities.Console; + +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class Craps implements Game { + Console console = Console.getConsole(); + private CrapsPlayer user = new CrapsPlayer(Casino.getProfile()); + private int initialBalance = getUser().getProfile().getBalance(); + private int adjustedBalance = 0; + private int betAmount = 0; + private final int[] anyCraps = {2, 3, 12}; + private final int[] hornBetRolls = {2, 3, 11, 12}; + private final int[] hardwaysRolls = {4, 6, 8, 10}; + private final int[] placeNumberRolls = {4, 5, 6, 8, 9, 10}; + private final int[] fieldNumberRolls = {2, 3, 4, 9, 10, 11, 12}; + private int point = 0; + private boolean isFirstRoll = true; + private int hardwaysRoll; + private boolean rollSumHardways = false; + private int placeBetChoice; + private int roll1; + private int roll2; + private int rollSum; + Dice die1 = new Dice(); + Dice die2 = new Dice(); + private GameStatus gameState; + + public void setIsFirstRoll(boolean isFirstRoll) { + this.isFirstRoll = isFirstRoll; + } + + public void setRollSum(int rollSum) { + this.rollSum = rollSum; + } + + public Map getBetMap() { + return betMap; + } + + public void setBetAmount(int betAmount) { + this.betAmount = betAmount; + } + + public int getAdjustedBalance() { + return adjustedBalance; + } + + public void setPoint(int point) { + this.point = point; + } + + public int getPoint() { + return point; + } + + public boolean getIsFirstRoll() { + return isFirstRoll; + } + + public void setBetInBetMap(String bet, boolean value) { + betMap.put(bet, value); + } + + public boolean getBetInBetMap(String bet) { + return betMap.get(bet); + } + + public void clearBets() { + betMap.put("Pass Bet", false); + betMap.put("Place Bet", false); + betMap.put("Lay Bet", false); + betMap.put("Any Craps", false); + betMap.put("The Field", false); + betMap.put("The Horn", false); + betMap.put("Hardways", false); + } + + public void setDie1(Dice dice) { + die1 = dice; + } + + public void setDie2(Dice dice) { + die2 = dice; + } + + public int getRollSum() { + return rollSum; + } + + public void setRollSumHardways(boolean rollSumHardways) { + this.rollSumHardways = rollSumHardways; + } + + public boolean getRollSumHardways() { + return rollSumHardways; + } + + public int getBetAmount() { + return betAmount; + } + + public void setAdjustedBalance(int adjustedBalance) { + this.adjustedBalance = adjustedBalance; + } + + public void setHardwaysRoll(int hardwaysRoll) { + this.hardwaysRoll = hardwaysRoll; + } + + public int getHardwaysRoll(){return hardwaysRoll;} + + public int getPlaceBetChoice() {return placeBetChoice;} + + public void setPlaceBetChoice(int placeBetChoice) { + this.placeBetChoice = placeBetChoice; + } + + public void setInitialBalance(int initialBalance) { + this.initialBalance = initialBalance; + } + + public int getInitialBalance(){return initialBalance;} + + public CrapsPlayer getUser() { + return user; + } + + private enum GameStatus {UNRESOLVED, WON, LOST} + + public enum BetList { + PLACE("always"), + LAY("always"), + ANYCRAPS("oneOff"), + FIELD("oneOff"), + HORN("oneOff"), + HARDWAYS("always"); + private String typeOfBet; + + BetList(String typeOfBet) { + this.typeOfBet = typeOfBet; + } + + public static Stream stream() { + return Stream.of(BetList.values()); + } + } + + private static Map betMap = new HashMap<>(); + + static { + betMap.put("Pass Bet", false); + betMap.put("Place Bet", false); + betMap.put("Lay Bet", false); + betMap.put("Any Craps", false); + betMap.put("The Field", false); + betMap.put("The Horn", false); + betMap.put("Hardways", false); + } + + private enum BetExplanations { + PLACE("The Place bet wins if the chosen number is rolled before a 7"), + LAY("The Lay bet wins if a 7 is rolled before the point"), + ANYCRAPS("Any Craps pays off on 2, 3 or 12 before rolling a 7"), + FIELD("The Field wins if 4, 5, 6, 8, 9 or 10 hits before 7"), + HORN("The Horn wins on 2, 3, 11 or 12 before rolling a 7"), + HARDWAYS("Hardways involves two dice of the same face value, which must be hit before 7 or the corresponding sum thrown 'easy'\n"); + private String betRules; + + BetExplanations(String betRules) { + this.betRules = betRules; + } + + public String getExplanations() { + return betRules; + } + + public static Stream stream() { + return Stream.of(BetExplanations.values()); + } + } + + public Craps() { + } + + // Purely for testing + public Craps(Console console) { + this.console = console; + } + + public void play() { + console.println(Greeter.getCrapsName()); + console.println("Welcome to the craps table!"); + setAdjustedBalance(getInitialBalance()); + while (getIsFirstRoll()) { + promptFirstBet(); + roll(); + evaluateFirstRoll(); + evaluateGameState(gameState); + } + while (gameState == GameStatus.UNRESOLVED) { + promptBet(); + roll(); + evaluate(); + evaluateGameState(gameState); + } + } + + public void evaluateFirstRoll() { + { + if (getBetInBetMap("Pass Bet")) { + if (Arrays.stream(anyCraps).anyMatch(i -> i == getRollSum())) { + gameState = GameStatus.LOST; + } else if (getRollSum() == 7 || getRollSum() == 11) { + gameState = GameStatus.WON; + } else { + setupGameplayLoop(); + } + } else if (!getBetInBetMap("Pass Bet")) { + if (getRollSum() == 7 || getRollSum() == 11) { + gameState = GameStatus.LOST; + } else if (Arrays.stream(anyCraps).anyMatch(i -> i == getRollSum())) { + gameState = GameStatus.UNRESOLVED; + } else { + setupGameplayLoop(); + } + } + } + } + + public void setupGameplayLoop() { + gameState = GameStatus.UNRESOLVED; + setPoint(rollSum); + setIsFirstRoll(false); + console.println("The point is now " + point + ".\n"); + } + + public void evaluateGameState(GameStatus gameState) { + if (gameState == GameStatus.WON) { + console.println("Your bet paid off!"); + adjustBalance(betAmount); + resetPointAndRoll(); + clearBets(); + promptQuit(); + } else if (gameState == GameStatus.LOST) { + console.println("You lost your bet!"); + adjustBalance(-betAmount); + resetPointAndRoll(); + clearBets(); + promptQuit(); + } else { + gameState = GameStatus.UNRESOLVED; + setIsFirstRoll(false); + } + } + + public void resetPointAndRoll() { + setPoint(0); + setIsFirstRoll(true); + } + + public void promptFirstBet() { + int betReturn = console.getIntegerInput("How much would you like to bet?"); + if (betReturn > adjustedBalance) { + console.println("You don't have that much, pal"); + promptFirstBet(); + } else { + betAmount = betReturn; + } + String passChoice = console.getStandardInput("Please choose 'Pass' or 'Don't Pass'"); + if (passChoice.equals("pass")) { + setBetInBetMap("Pass Bet", true); + } else if (passChoice.equals("don't pass")) { + setBetInBetMap("Pass Bet", false); + } else { + console.println("I don't know that one, ace. Try again."); + promptFirstBet(); + } + } + + public void promptBet() { + int betChoice = console.getIntegerInput("You have five choices:\n1) Explain Possible Bets\n2) List Current Bets\n3) List Available Bets\n4) Make a Bet\n5) Continue Rolling"); + switch (betChoice) { + case 1: + betRulesListed(); + promptBet(); + break; + case 2: + console.println("You have the current bets: " + currentBetList(true) + "\n"); + promptBet(); + break; + case 3: + listBets(); + promptBet(); + break; + case 4: + makeBet(); + break; + case 5: + break; + } + } + + public void makeBet() { + String betName = console.getStandardInput("What bet would you like to place?"); + switch (betName) { + case "place": + setBetInBetMap("Place Bet", true); + setPlaceBetChoice(console.getIntegerInput("What number do you want to make a Place Bet for?")); + if (Arrays.stream(placeNumberRolls).anyMatch(i -> i == getPlaceBetChoice())) { + console.println("Excellent choice!"); + } else { + setPlaceBetChoice(console.getIntegerInput("Stick to the Place numbers, buddy! Pick from 4, 5, 6, 8, 9 or 10")); + } + break; + case "lay": + setBetInBetMap("Lay Bet", true); + break; + case "anycraps": + setBetInBetMap("Any Craps", true); + break; + case "field": + setBetInBetMap("The Field", true); + break; + case "horn": + setBetInBetMap("The Horn", true); + break; + case "hardways": + setBetInBetMap("Hardways", true); + setHardwaysRoll(console.getIntegerInput("What number do you want to place a Hardways Bet on?")); + if (Arrays.stream(hardwaysRolls).anyMatch(i -> i == getHardwaysRoll())) { + console.println("Excellent choice!\n"); + } else { + setHardwaysRoll(console.getIntegerInput("Stick to the Place numbers, buddy! Pick from 4, 6, 8, or 10")); + } + break; + default: + console.println("Please enter an actual bet, pal"); + makeBet(); + } + } + + public void betRulesListed() { + for (BetExplanations bet : BetExplanations.values()) { + console.println(bet.getExplanations()); + } + } + + public void filteredBetList(String betOptions) { + BetList.stream() + .filter(e -> e.typeOfBet.equals(betOptions)) + .forEach(console::println); + } + + public List currentBetList(boolean value) { + return betMap + .entrySet() + .stream() + .filter(e -> Objects.equals(e.getValue(), value)) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + } + + public void listBets() { + int betList = console.getIntegerInput("Choose one of the follow:\n1) List Bets always available\n2) List one-off Bets\n3) Go to previous Menu"); + switch (betList) { + case 1: + filteredBetList("always"); + break; + case 2: + filteredBetList("oneOff"); + break; + case 3: + promptBet(); + break; + } + } + + public int roll() { + roll1 = die1.roll(); + roll2 = die2.roll(); + setRollSum(roll1 + roll2); + if (roll1 == roll2) { + rollSumHardways = true; + } else { + rollSumHardways = false; + } + console.println("\nHERE ARE YOUR DIE:\n" + Dice.getDiceString(roll1, roll2)); + return getRollSum(); + } + + public void evaluate() { + if (rollSum == 7) { + evaluate7s(); + } else if (Arrays.stream(anyCraps).anyMatch(i -> i == getRollSum())) { + evaluateCrappedRolls(); + } else evaluatePointRolls(); + } + + public void evaluate7s() { + if (getBetInBetMap("Lay Bet")) { + gameState = GameStatus.WON; + } else if (!getBetInBetMap("Pass Bet")) { + gameState = GameStatus.WON; + } else { + gameState = GameStatus.LOST; + } + } + + public void evaluateCrappedRolls() { + if (!getIsFirstRoll() && gameState == GameStatus.UNRESOLVED) { + if (getBetInBetMap("Any Craps") && Arrays.stream(anyCraps).anyMatch(i -> i == getRollSum())) { + gameState = GameStatus.WON; + } + if (getBetInBetMap("Any Craps") && Arrays.stream(anyCraps).noneMatch(i -> i == getRollSum())) { + gameState = GameStatus.LOST; + } + } + } + + public void evaluatePointRolls() { + { + if (getBetInBetMap("The Field") && Arrays.stream(fieldNumberRolls).anyMatch(i -> i == getRollSum())) { + gameState = GameStatus.WON; + } + if (getBetInBetMap("The Horn") && Arrays.stream(hornBetRolls).anyMatch(i -> i == getRollSum())) { + gameState = GameStatus.WON; + } + if (getBetInBetMap("Hardways") && (roll1 == roll2) && getHardwaysRoll() == getRollSum()) { + gameState = GameStatus.WON; + } + if (getBetInBetMap("Lay Bet") && getRollSum() == 7) { + gameState = GameStatus.WON; + } + if (getPoint() == getRollSum() && getBetInBetMap("Pass Bet")) { + console.println("Lucky number " + point + "! You hit the point!\n"); + gameState = GameStatus.WON; + } + if (getRollSum() == placeBetChoice) { + gameState = GameStatus.WON; + promptQuit(); + } else { + console.println("Nothing won yet...\n"); + } + } + } + + public void promptQuit() { + String quitPrompt = console.getStandardInput("Would you like to quit while you're ahead?"); + if (quitPrompt.equals("yes")) { + cashOut(); + } else { + console.println("Okay, you're a responsible adult, and you know your limits\n"); + gameState = GameStatus.UNRESOLVED; + resetPointAndRoll(); + } + } + + public void adjustBalance(int profitOrLoss) { + if (profitOrLoss > 0) { + console.println(String.format("You're on a roll and %d NUCs richer!\n", profitOrLoss)); + } else if (profitOrLoss < 0) { + console.println(String.format("%d NUCs gone already? Play again to win that back and more!\n", profitOrLoss)); + } + adjustedBalance += profitOrLoss; + } + + public void compareBalance() { + if (adjustedBalance > initialBalance) { + console.println(String.format("You won %d NUCs!\n", (adjustedBalance - initialBalance))); + } else if (adjustedBalance < initialBalance) { + console.println(String.format("You're %d NUCs poorer!\n", (initialBalance - adjustedBalance))); + } else { + console.println("You broke even!\n"); + } + } + + public void cashOut() { + String continuePlaying = console.getStandardInput("Wouldn't you rather continue playing?"); + if (continuePlaying.equals("no")) { + compareBalance(); + user.getProfile().setBalance(adjustedBalance); + } + } +} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/casino/games/dicegames/CrapsPlayer.java b/src/main/java/io/zipcoder/casino/casino/games/dicegames/CrapsPlayer.java new file mode 100644 index 000000000..8a563a6fa --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/dicegames/CrapsPlayer.java @@ -0,0 +1,9 @@ +package io.zipcoder.casino.casino.games.dicegames; +import io.zipcoder.casino.casino.Player; +import io.zipcoder.casino.casino.Profile; + +public class CrapsPlayer extends Player { + public CrapsPlayer(Profile profile){ + super(profile); + } +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/dicegames/Macao.java b/src/main/java/io/zipcoder/casino/casino/games/dicegames/Macao.java new file mode 100644 index 000000000..e629f566b --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/dicegames/Macao.java @@ -0,0 +1,207 @@ +package io.zipcoder.casino.casino.games.dicegames; + +import io.zipcoder.casino.casino.games.dicegames.diceutilities.Dice; +import io.zipcoder.casino.casino.games.Game; +import io.zipcoder.casino.casino.Casino; +import io.zipcoder.casino.casino.Greeter; +import io.zipcoder.casino.casino.utilities.Console; + +public class Macao implements Game { + + private MacaoPlayer user; + private MacaoPlayer dealer; + private boolean isOver; + private Dice dice; + private Console console; + private boolean guestStillPlaying; + private boolean dealerStillPlaying; + + + public Macao() { + this.user = new MacaoPlayer(Casino.getProfile()); + this.dealer = new MacaoPlayer(); + this.isOver = false; + this.dice = new Dice(); + this.console = Console.getConsole(); + this.guestStillPlaying = true; + this.dealerStillPlaying = true; + } + + public Macao(Console console) { + this.user = new MacaoPlayer(Casino.getProfile()); + this.dealer = new MacaoPlayer(); + this.isOver = false; + this.dice = new Dice(); + this.console = console; + this.guestStillPlaying = true; + this.dealerStillPlaying = true; + } + + public MacaoPlayer getUser() { + return user; + } + + public MacaoPlayer getDealer() { + return dealer; + } + + public void setConsole(Console console) { + this.console = console; + } + + public boolean getIsOver() { + return isOver; + } + + public void setIsOver(boolean gameOver) { + this.isOver = gameOver; + } + + public void setDice(Dice dice) { + this.dice = dice; + } + + public boolean getGuestStillPlaying() { + return guestStillPlaying; + } + + public void setGuestStillPlaying(boolean stillPlaying) { + this.guestStillPlaying = stillPlaying; + } + + public boolean getDealerStillPlaying() { + return dealerStillPlaying; + } + + public void setDealerStillPlaying(boolean stillPlaying) { + this.dealerStillPlaying = stillPlaying; + } + + public void play() { + console.println(Greeter.getMacaoName()); + printGameInstructions(); + if (beginGame()) { + initialGameSetup(); + } + while (!isOver) { + if (isGuestStillPlaying()) { + rollDie(user); + showGuestRoll(); + } + if (didGuestGoOver()) { + youWentOver(); + break; + } + if (isDealerStillPlaying()) { + rollDie(dealer); + showDealerRoll(); + } + evaluate(); + } + user.getProfile().setBalance(user.getProfile().getBalance() - 5); + } + + public void printGameInstructions() { + console.println("Rules:\nThe object of this game is to roll the die enough times to reach a total of 9 without going over.\nGood luck!\n"); + } + + public boolean beginGame() { + boolean beginGame = false; + for (int i = 0; i < 1; i++) { + String begin = console.getStandardInput("Are you ready to begin?"); + if (begin.equals("y") || begin.equals("yes")) { + beginGame = true; + } else { + console.print("Hm, I expected something different. "); + i--; + } + } + return beginGame; + } + + public void rollDie(MacaoPlayer player) { + player.setRoll(dice.roll()); + } + + public void showInitialRolls() { + console.println("YOUR ROLL DEALER'S ROLL\n%s", Dice.getDiceStringWithSpace(user.getRoll(), dealer.getRoll())); + } + + public void showGuestRoll() { + console.println("YOUR NEW ROLL\n%sYOUR TOTAL IS NOW... %s\nHERE'S WHAT YOU ROLLED SO FAR\n%s", Dice.getDiceStringWithSpace(user.getRoll()), user.getCumulativeRoll(), Dice.getDiceString(user.getDiceRolls())); + } + + public void showDealerRoll() { + console.println("DEALERS'S NEW ROLL\n%sTHE DEALERS'S TOTAL IS NOW... %s\nHERE'S WHAT THE DEALER ROLLED SO FAR\n%s", Dice.getDiceString(dealer.getRoll()), dealer.getCumulativeRoll(), Dice.getDiceString(dealer.getDiceRolls())); + } + + public void initialGameSetup() { + rollDie(user); + rollDie(dealer); + showInitialRolls(); + } + + public boolean isGuestStillPlaying() { + if (user.getCumulativeRoll() == 9) { + guestStillPlaying = false; + } + for (int i = 0; i < 1; i++) { + if (user.getCumulativeRoll() < 9 && guestStillPlaying) { + String yesOrNo = console.getStandardInput("Would you like to roll again?"); + if (yesOrNo.equals("yes") || yesOrNo.equals("y")) { + console.println("Great, here's your die."); + } else if(yesOrNo.equals("no") || yesOrNo.equals("n")) { + console.println("Bold tactic."); + guestStillPlaying = false; + } else { + console.println("I didn't catch that."); + i--; + } + } + } + return guestStillPlaying; + } + + public void youWentOver() { + console.println("Oh no! Looks like you went over! You lose."); + } + + public boolean didGuestGoOver() { + boolean guestWentOver = false; + if (user.getCumulativeRoll() > 9) { + guestStillPlaying = false; + return true; + } + return guestWentOver; + } + + public boolean isDealerStillPlaying() { + if (dealerStillPlaying) { + if (dealer.getCumulativeRoll() > 6 && dealer.getCumulativeRoll() > user.getCumulativeRoll()) { + dealerStillPlaying = false; + } + if (dealer.getCumulativeRoll() > 7) { + dealerStillPlaying = false; + } + } + return dealerStillPlaying; + } + + public void evaluate() { + if (dealer.getCumulativeRoll() > 9) { + console.println("Lucky you! The dealer went over. YOU WIN!"); + isOver = true; + } else if (!guestStillPlaying && !dealerStillPlaying) { + isOver = true; + if (user.getCumulativeRoll() > dealer.getCumulativeRoll()) { + console.println("Your total is %s and the dealer's total is %s. You're our winner!", user.getCumulativeRoll(), dealer.getCumulativeRoll()); + } else if (dealer.getCumulativeRoll() > user.getCumulativeRoll()) { + console.println("Your total is %s and the dealer's total is %s. Better luck next time.", user.getCumulativeRoll(), dealer.getCumulativeRoll()); + } else if (user.getCumulativeRoll() == dealer.getCumulativeRoll()) { + console.println("You both rolled %s. It's a tie!", user.getCumulativeRoll()); + } + } + } + + +} diff --git a/src/main/java/io/zipcoder/casino/casino/games/dicegames/MacaoPlayer.java b/src/main/java/io/zipcoder/casino/casino/games/dicegames/MacaoPlayer.java new file mode 100644 index 000000000..70114d815 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/dicegames/MacaoPlayer.java @@ -0,0 +1,57 @@ +package io.zipcoder.casino.casino.games.dicegames; + +import io.zipcoder.casino.casino.Player; +import io.zipcoder.casino.casino.Profile; + +import java.util.ArrayList; + +public class MacaoPlayer extends Player { + + private int roll; + private int cumulativeRoll; + private ArrayList diceRolls; + + public MacaoPlayer() { + super(); + this.roll = 0; + this.cumulativeRoll = 0; + this.diceRolls = new ArrayList<>(); + } + + public MacaoPlayer(Profile profile) { + super(profile); + this.roll = 0; + this.cumulativeRoll = 0; + this.diceRolls = new ArrayList<>(); + } + + public Profile getProfile() { + return super.getProfile(); + } + + public int getRoll() { + return roll; + } + + public int getCumulativeRoll() { + return cumulativeRoll; + } + + public void setRoll(int roll) { + this.roll = roll; + this.cumulativeRoll += roll; + diceRolls.add(roll); + } + + + + public ArrayList getDiceRolls() { + return diceRolls; + } + + public void setCumulativeRoll(int roll) { + this.cumulativeRoll = roll; + } +} + + diff --git a/src/main/java/io/zipcoder/casino/casino/games/dicegames/diceutilities/Dice.java b/src/main/java/io/zipcoder/casino/casino/games/dicegames/diceutilities/Dice.java new file mode 100644 index 000000000..e993aae69 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/dicegames/diceutilities/Dice.java @@ -0,0 +1,77 @@ +package io.zipcoder.casino.casino.games.dicegames.diceutilities; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +public class Dice { + private static final HashMap stringRepresentations= new HashMap<>(); + static { + stringRepresentations.put(1, new String[]{"\u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513", + "\u2503 \u2503", "\u2503 \u2B24 \u2503", + "\u2503 \u2503", "\u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B"}); + stringRepresentations.put(2, new String[]{"\u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513", + "\u2503 \u2B24 \u2503", "\u2503 \u2503", + "\u2503 \u2B24 \u2503", "\u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B"}); + stringRepresentations.put(3, new String[]{"\u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513", + "\u2503 \u2B24 \u2503", "\u2503 \u2B24 \u2503", + "\u2503 \u2B24 \u2503", "\u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B"}); + stringRepresentations.put(4, new String[]{"\u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513", + "\u2503 \u2B24 \u2B24 \u2503", "\u2503 \u2503", + "\u2503 \u2B24 \u2B24 \u2503", "\u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B"}); + stringRepresentations.put(5, new String[]{"\u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513", + "\u2503 \u2B24 \u2B24 \u2503", "\u2503 \u2B24 \u2503", + "\u2503 \u2B24 \u2B24 \u2503", "\u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B"}); + stringRepresentations.put(6, new String[]{"\u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513", + "\u2503 \u2B24 \u2B24 \u2503", "\u2503 \u2B24 \u2B24 \u2503", + "\u2503 \u2B24 \u2B24 \u2503", "\u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B"}); + } + + + public Dice() { + } + + public int roll() { + return (int)(Math.random()*6 + 1); + } + +// public static String getDieString(Integer dieNumber) { +// StringBuilder dieRepresentation = new StringBuilder(); +// for (String row: stringRepresentations.get(dieNumber)) { +// dieRepresentation.append(row + "\n"); +// } +// return dieRepresentation.toString(); +// } + + + public static String getDiceString(Integer... diceNumbers) { + List diceList = new ArrayList<>(Arrays.asList(diceNumbers)); + return getDiceString(diceList); + } + + public static String getDiceString(List diceNumbers) { + StringBuilder allDicePrinted = new StringBuilder(); + for (int i = 0; i < 5; i++) { + for (int number : diceNumbers) { + allDicePrinted.append(stringRepresentations.get(number)[i]); + } + allDicePrinted.append("\n"); + } + return allDicePrinted.toString(); + } + + public static String getDiceStringWithSpace(Integer... diceNumbers) { + StringBuilder allDicePrinted = new StringBuilder(); + for (int i = 0; i < 5; i++) { + for (int number : diceNumbers) { + allDicePrinted.append(stringRepresentations.get(number)[i] + " "); + } + allDicePrinted.append("\n"); + } + return allDicePrinted.toString(); + } + + +} + diff --git a/src/main/java/io/zipcoder/casino/casino/games/dicegames/diceutilities/LoadedDice.java b/src/main/java/io/zipcoder/casino/casino/games/dicegames/diceutilities/LoadedDice.java new file mode 100644 index 000000000..169397f99 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/casino/games/dicegames/diceutilities/LoadedDice.java @@ -0,0 +1,15 @@ +package io.zipcoder.casino.casino.games.dicegames.diceutilities; + +public class LoadedDice extends Dice { + private int numberToRoll; + + public LoadedDice(int numberToRoll) { + this.numberToRoll = numberToRoll; + } + + @Override + public int roll() { + return numberToRoll; + } + +} diff --git a/src/main/java/io/zipcoder/casino/utilities/Console.java b/src/main/java/io/zipcoder/casino/casino/utilities/Console.java similarity index 62% rename from src/main/java/io/zipcoder/casino/utilities/Console.java rename to src/main/java/io/zipcoder/casino/casino/utilities/Console.java index ab896c956..3223f93a7 100644 --- a/src/main/java/io/zipcoder/casino/utilities/Console.java +++ b/src/main/java/io/zipcoder/casino/casino/utilities/Console.java @@ -1,6 +1,8 @@ -package io.zipcoder.casino.utilities; +package io.zipcoder.casino.casino.utilities; +import io.zipcoder.casino.casino.games.dicegames.Craps; + import java.io.InputStream; import java.io.PrintStream; import java.util.Scanner; @@ -8,21 +10,44 @@ /** * You are advised against modifying this class. */ + public final class Console { private final Scanner input; private final PrintStream output; + private static Console console = null; + + // Console to be a Singleton outside of testing + public static Console getConsole() + { + if (console == null) + console = new Console(); + return console; + } + private Console() { + this(System.in, System.out); + } + // Public Constructors for testing public Console(InputStream in, PrintStream out) { this.input = new Scanner(in); this.output = out; } + public Console(Scanner scanner, PrintStream out) { + this.input = scanner; + this.output = out; + } + public void print(String val, Object... args) { output.format(val, args); } - public void println(String val, Object... vals) { - print(val + "\n", vals); + public void println(String val, Object... args) { + print(val + "\n", args); + } + + public void println(Craps.BetList betList) { + print(betList.toString() + "\n"); } public String getStringInput(String prompt, Object... args) { @@ -30,6 +55,14 @@ public String getStringInput(String prompt, Object... args) { return input.nextLine(); } + public String getStandardInput(String prompt, Object... args) { + return getStringInput(prompt, args).trim().toLowerCase(); + } + + public String getStandardInputCaps(String prompt, Object... args) { + return getStringInput(prompt, args).trim().toUpperCase(); + } + public Double getDoubleInput(String prompt, Object... args) { String stringInput = getStringInput(prompt, args); try { @@ -57,5 +90,7 @@ public Long getLongInput(String prompt, Object... args) { public Integer getIntegerInput(String prompt, Object... args) { return getLongInput(prompt, args).intValue(); } + + } diff --git a/src/test/java/io/zipcoder/casino/CasinoTest.java b/src/test/java/io/zipcoder/casino/CasinoTest.java deleted file mode 100644 index e92865236..000000000 --- a/src/test/java/io/zipcoder/casino/CasinoTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.zipcoder.casino; - - -public class CasinoTest { -} diff --git a/src/test/java/io/zipcoder/casino/casino/CasinoTest.java b/src/test/java/io/zipcoder/casino/casino/CasinoTest.java new file mode 100644 index 000000000..9ffe2818c --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/CasinoTest.java @@ -0,0 +1,325 @@ +package io.zipcoder.casino.casino; + + +import io.zipcoder.casino.casino.games.cardgames.BlackJack; +import io.zipcoder.casino.casino.games.Game; +import io.zipcoder.casino.casino.games.cardgames.GoFish; +import io.zipcoder.casino.casino.games.dicegames.Macao; +import io.zipcoder.casino.casino.utilities.Console; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + +public class CasinoTest { + @Test + public void greetUserTest() { + // Given + String input = "testName\n18\nyes"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + + // When + Casino.greetUser(); + String actual = Casino.getProfile().getName(); + + // Then + String expected = "testName"; + Assert.assertEquals(expected, actual); + Assert.assertTrue(Casino.getProfile().isGambler()); + } + + @Test + public void greetUserTest2() { + // Given + String input = "name\n1"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + + // When + Casino.greetUser(); + String actual = Casino.getProfile().getName(); + + // Then + String expected = "name"; + Assert.assertEquals(expected, actual); + Assert.assertFalse(Casino.getProfile().isGambler()); + } + + @Test + public void greetUserTest3() { + // Given + String input = "othername\n45\nno"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + + // When + Casino.greetUser(); + String actual = Casino.getProfile().getName(); + + // Then + String expected = "othername"; + Assert.assertEquals(expected, actual); + Assert.assertFalse(Casino.getProfile().isGambler()); + } + + @Test + public void testGetNextClean() { + // Given + String input = "macao"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextCleanGame(); + + // Then + Assert.assertTrue(game instanceof Macao); + } + + @Test + public void testGetNextClean2() { + // Given + String input = "gofish"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextCleanGame(); + + // Then + Assert.assertTrue(game instanceof GoFish); + } + + @Test + public void testGetNextClean3() { + // Given + String input = "blackjack"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextCleanGame(); + + // Then + Assert.assertTrue(game instanceof GoFish); + } + + @Test + public void offerUserGames() { + // Given + String input = "othername\n45\nno\nmacao"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + + // When + Casino.greetUser(); + Game game = Casino.offerUserGames(); + + // Then + Assert.assertTrue(game instanceof Macao); + } + + @Test + public void offerUserGames2() { + // Given + String input = "othername\n45\nyes\ngasdfasdf"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + + // When + Casino.greetUser(); + Game game = Casino.offerUserGames(); + + // Then + Assert.assertTrue(game instanceof GoFish); + } + + @Test + public void offerUserGames3() { + // Given + String input = "othername\n45\nyes\nblackjack"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + + // When + Casino.greetUser(); + Game game = Casino.offerUserGames(); + + // Then + Assert.assertTrue(game instanceof BlackJack); + } + + + @Test + public void offerUserLeaveTest() { + // Given + String input = "no"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + + // When + Casino.setProfile(); + Casino.offerUserLeave(); + + // Then + Assert.assertTrue(Casino.isUserIsLeaving()); + } + + @Test + public void offerUserLeaveTest2() { + // Given + String input = "yes"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + + // When + Casino.setProfile(); + Casino.offerUserLeave(); + + // Then + Assert.assertFalse(Casino.isUserIsLeaving()); + } + + @Test + public void offerUserLeaveTest3() { + // Given + String input = "asdfasdf"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + + // When + Casino.setProfile(); + Casino.offerUserLeave(); + + // Then + Assert.assertFalse(Casino.isUserIsLeaving()); + } + + @Test + public void offerUserLeaveTest4() { + // Given + String input = "yes"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + + // When + Casino.setProfile(); + Casino.getProfile().setBalance(0); + Casino.offerUserLeave(); + + // Then + Assert.assertTrue(Casino.isUserIsLeaving()); + } + + @Test + public void seeUserOutTest() { + // Given + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + String expected = "Thank you so much for coming! Please come again!\n"; + + // When + Casino.seeUserOut(); + + // Then + String actual = outputStream.toString(); + Assert.assertTrue(actual.contains(expected)); + } + + @Test + public void entertainUserTest() { + // Given + String input = "testname\n1\ntestingcheatsenabledtrue\nno"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + + Casino.setGreeter(greeter); + + // When + Casino.setProfile(); + Casino.entertainUser(); + String actual = outputStream.toString(); + + // Then + Assert.assertTrue(Casino.isUserIsLeaving()); + Assert.assertTrue(actual.contains("Thank you so much for coming! Please come again!") && + actual.contains("Welcome to our casino! What's your name?")); + } + + @Test + public void mainTest() { + // Given + String input = "testname\n1\ntestingcheatsenabledtrue\nno"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + Casino.setGreeter(greeter); + Casino.setProfile(); + + // When + Casino.main(new String[0]); + String actual = outputStream.toString(); + + // Then + Assert.assertTrue(Casino.isUserIsLeaving()); + Assert.assertTrue(actual.contains("Thank you so much for coming! Please come again!") && + actual.contains("Welcome to our casino! What's your name?")); + } +} diff --git a/src/test/java/io/zipcoder/casino/casino/ConsoleTest.java b/src/test/java/io/zipcoder/casino/casino/ConsoleTest.java new file mode 100644 index 000000000..7e88bd97c --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/ConsoleTest.java @@ -0,0 +1,318 @@ +package io.zipcoder.casino.casino; + +import io.zipcoder.casino.casino.utilities.Console; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.NoSuchElementException; +import java.util.Scanner; + +public class ConsoleTest { + + @Test + public void testPrint1() { + + // Given + String input = "Welcome to the number 1 casino!"; + String expected = String.format(input); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + + // When + console.print(input); + String actual = outputStream.toString(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testPrint2() { + + // Given + String input = "Welcome to the number %s casino!"; + String[] arguments = {"1"}; + String expected = String.format(input, arguments); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + + // When + console.print(input, arguments); + String actual = outputStream.toString(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testPrintLn1() { + // Given + String input = "Welcome to the number 1 casino!"; + String expected = String.format(input + "\n"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + + // When + console.println(input); + String actual = outputStream.toString(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testPrintLn2() { + // Given + String input = "Welcome to the number %s casino!"; + String[] arguments = {"1"}; + String expected = String.format(input + "\n", arguments); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + + // When + console.println(input, arguments); + String actual = outputStream.toString(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetStringInput1() { + // Given + String expectedInput = "I want to play blackjack"; + byte[] inputBytes = expectedInput.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + + // When + String actualInput = console.getStringInput("What do you want to play?"); + + // Then + Assert.assertEquals(expectedInput, actualInput); + } + + @Test + public void testGetStringInput2() { + // Given + String expectedInput = "test answer"; + byte[] inputBytes = expectedInput.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + + // When + String actualInput = console.getStringInput("testPrompt"); + + // Then + Assert.assertEquals(expectedInput, actualInput); + } + + @Test + public void testGetStandardInput() { + // Given + String input = "test answer"; + byte[] inputBytes = input.getBytes(); + String expectedInput = input.toLowerCase().trim(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + + // When + String actualInput = console.getStandardInput(" "); + + // Then + Assert.assertEquals(expectedInput, actualInput); + } + + @Test + public void testGetStandardInput2() { + // Given + String input = "adfs;jafdsjpafjpi"; + byte[] inputBytes = input.getBytes(); + String expectedInput = input.toLowerCase().trim(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + + // When + String actualInput = console.getStandardInput(" "); + + // Then + Assert.assertEquals(expectedInput, actualInput); + } + + @Test + public void testGetStandardInputCaps() { + // Given + String input = "test answer"; + byte[] inputBytes = input.getBytes(); + String expectedInput = input.toUpperCase().trim(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + + // When + String actualInput = console.getStandardInputCaps(" "); + + // Then + Assert.assertEquals(expectedInput, actualInput); + } + + @Test + public void testGetStandardInputCaps2() { + // Given + String input = "adfs;jafdsjpafjpi"; + byte[] inputBytes = input.getBytes(); + String expectedInput = input.toUpperCase().trim(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + + // When + String actualInput = console.getStandardInputCaps(" "); + + // Then + Assert.assertEquals(expectedInput, actualInput); + } + + @Test + public void testGetIntegerInput1() { + // Given + byte[] inputBytes = "0".getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Scanner scanner = new Scanner(inputByteArray); + Console console = new Console(scanner, System.out); + + // When + Integer actual = console.getIntegerInput(""); + Integer expected = 0; + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetIntegerInput2() { + // Given + byte[] inputBytes = "9000".getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Scanner scanner = new Scanner(inputByteArray); + Console console = new Console(scanner, System.out); + + // When + Integer actual = console.getIntegerInput("What are you over?"); + Integer expected = 9000; + + // Then + Assert.assertEquals(expected, actual); + } + + + @Test(expected=NoSuchElementException.class) + public void testGetIntegerInput3() { + // Given + byte[] inputBytes = "Somethingelse".getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Scanner scanner = new Scanner(inputByteArray); + String expected = String.format("[ %s ] is an invalid user input!", "Somethingelse"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(scanner, new PrintStream(outputStream)); + + // When + console.getIntegerInput("Don't type in words"); + } + + @Test + public void testGetLongInput1() { + // Given + byte[] inputBytes = "0".getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Scanner scanner = new Scanner(inputByteArray); + Console console = new Console(scanner, System.out); + + // When + Long actual = console.getLongInput(""); + Long expected = 0L; + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetLongInput2() { + // Given + byte[] inputBytes = "9000".getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Scanner scanner = new Scanner(inputByteArray); + Console console = new Console(scanner, System.out); + + // When + Long actual = console.getLongInput("What are you over?"); + Long expected = 9000L; + + // Then + Assert.assertEquals(expected, actual); + } + + + @Test(expected=NoSuchElementException.class) + public void testGetLongInput3() { + // Given + byte[] inputBytes = "Somethingelse".getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Scanner scanner = new Scanner(inputByteArray); + String expected = String.format("[ %s ] is an invalid user input!", "Somethingelse"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(scanner, new PrintStream(outputStream)); + + // When + console.getLongInput("Don't type in words"); + } + + @Test + public void testGetDoubleInput1() { + // Given + byte[] inputBytes = "0".getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Scanner scanner = new Scanner(inputByteArray); + Console console = new Console(scanner, System.out); + + // When + Double actual = console.getDoubleInput(""); + Double expected = 0.0; + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetDoubleInput2() { + // Given + byte[] inputBytes = "9000".getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Scanner scanner = new Scanner(inputByteArray); + Console console = new Console(scanner, System.out); + + // When + Double actual = console.getDoubleInput("What are you over?"); + Double expected = 9000.0; + + // Then + Assert.assertEquals(expected, actual); + } + + + @Test(expected=NoSuchElementException.class) + public void testGetDoubleInput3() { + // Given + byte[] inputBytes = "Somethingelse".getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Scanner scanner = new Scanner(inputByteArray); + String expected = String.format("[ %s ] is an invalid user input!", "Somethingelse"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(scanner, new PrintStream(outputStream)); + + // When + console.getDoubleInput("Don't type in words"); + } + +} diff --git a/src/test/java/io/zipcoder/casino/casino/DiceTest.java b/src/test/java/io/zipcoder/casino/casino/DiceTest.java new file mode 100644 index 000000000..7cd06fa29 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/DiceTest.java @@ -0,0 +1,41 @@ +package io.zipcoder.casino.casino; + +import io.zipcoder.casino.casino.games.dicegames.diceutilities.Dice; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; + +public class DiceTest { + + private Dice dice = new Dice(); + + @Test + public void rollTest() { + // Given an ArrayList that stores output from the roll method (and an expected mininum of 1 and maximum of 6) + ArrayList ints = new ArrayList<>(); + Integer expectedMinimum = 1; + Integer expectedMaximum = 6; + + // When the roll function is called 1000 times and the variables stored in the int arraylist + for (int i = 0; i < 1000; i++) { + ints.add(dice.roll()); + } + + // When we retrieve the minimum and maximum values + Integer actualMinimum = ints.get(0); + Integer actualMaximum = ints.get(0); + for (int i = 1; i < ints.size(); i++) { + if (ints.get(i) < actualMinimum) { + actualMinimum = ints.get(i); + } + if (ints.get(i) > actualMaximum) { + actualMaximum = ints.get(i); + } + } + + // Then we expect the mins and maxes to match + Assert.assertEquals(expectedMaximum, actualMaximum); + Assert.assertEquals(expectedMinimum, actualMinimum); + } +} diff --git a/src/test/java/io/zipcoder/casino/casino/GameTest/BlackJackTest.java b/src/test/java/io/zipcoder/casino/casino/GameTest/BlackJackTest.java new file mode 100644 index 000000000..4338d5361 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/GameTest/BlackJackTest.java @@ -0,0 +1,759 @@ +package io.zipcoder.casino.casino.GameTest; + +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Card; +import io.zipcoder.casino.casino.games.cardgames.BlackJack; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Rank; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Suit; +import io.zipcoder.casino.casino.games.cardgames.BlackJackPlayer; +import io.zipcoder.casino.casino.utilities.Console; +import org.junit.Assert; +import org.junit.Test; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.List; + + +public class BlackJackTest { + + private Console console; + private int userTotal; + private int dealerTotal; + private int userBet; + + @Test + public void testTakingUserBet() { + String input = "10\n"; + ByteArrayInputStream bais = new ByteArrayInputStream(input.getBytes()); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console testConsole = new Console(bais, new PrintStream(baos)); + + String output = baos.toString(); + + //Given + BlackJack blackJack = new BlackJack(testConsole); + blackJack.getUserBet(); + + //Then + Assert.assertEquals((int)blackJack.getUserBetAsInteger(), 10); + } + + @Test + public void testTakeUserBetWithInsult(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("2000\n200",baos); + BlackJack newBlkJ = new BlackJack(console); + newBlkJ.getUser().setBalance(1000); + //When + newBlkJ.getUserBet(); + //Then + Assert.assertTrue(baos.toString().contains("Place a bet if you DARE")); + Assert.assertTrue(baos.toString().contains("Your broke ass has insufficient funds..")); + } + @Test + public void testTakeUserBetWithInsultCheckUserBet(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("2000\n200",baos); + BlackJack newBlkJ = new BlackJack(console); + newBlkJ.getUser().setBalance(1000); + int expected = 200; + + //When + newBlkJ.getUserBet(); + + //Then + Assert.assertEquals(expected,(int)newBlkJ.getUserBetAsInteger()); + } + @Test + public void testTakeUserBetWithInsultCheckBalance(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("2000\n200",baos); + BlackJack newBlkJ = new BlackJack(console); + BlackJackPlayer testPlayer = newBlkJ.getUser(); + newBlkJ.getUser().setBalance(1000); + int expected = 800; + + //When + newBlkJ.getUserBet(); + int actual = testPlayer.getProfile().getBalance(); + + //Then + Assert.assertEquals(expected,actual); + } + + @Test + public void testTellUserDeyPoor(){ + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(null ,baos); + BlackJack newBlkJ = new BlackJack(console); + + //When + newBlkJ.tellUserDeyPoor(); + + //Then + Assert.assertTrue(baos.toString().contains("Your broke ass has insufficient funds..")); + } + @Test + public void testDealFirstHand(){ + + BlackJack newBlkJ = new BlackJack(); + int expected = 2; + + //When + newBlkJ.dealFirstHand(); + + //Then + Assert.assertEquals(expected, newBlkJ.getUser().getHand().size()); + Assert.assertEquals(expected, newBlkJ.getDealer().getHand().size()); + } + @Test + public void testGetTotal(){ + //Given + BlackJack newBlkJ = new BlackJack(); + List testHand = new ArrayList(); + Card c1 = new Card(Suit.DIAMONDS,Rank.NINE); + Card c2 = new Card(Suit.SPADES, Rank.QUEEN); + Card c3 = new Card(Suit.HEARTS, Rank.SIX); + + testHand.add(c1); + testHand.add(c2); + testHand.add(c3); + + //When + int actual = newBlkJ.getTotal(testHand); + int expected = 25; + + //Then + Assert.assertEquals(expected, actual); + + } + @Test + public void testGetTotalAcesOver21(){ + //Given + BlackJack newBlkJ = new BlackJack(); + List testHand = new ArrayList(); + Card c1 = new Card(Suit.DIAMONDS,Rank.NINE); + Card c2 = new Card(Suit.SPADES, Rank.QUEEN); + Card c3 = new Card(Suit.HEARTS, Rank.ACE); + Card c4 = new Card(Suit.CLUBS, Rank.ACE); + + testHand.add(c1); + testHand.add(c2); + testHand.add(c3); + testHand.add(c4); + + //When + int actual = newBlkJ.getTotal(testHand); + int expected = 21; + + //Then + Assert.assertEquals(expected, actual); + + } + + @Test + public void testAcesTotalOneEleven(){ + //Given + BlackJack blackJack = new BlackJack(); + List testH = new ArrayList(); + Card card1 = new Card(Suit.SPADES, Rank.ACE); + Card card2 = new Card(Suit.DIAMONDS, Rank.ACE); + + //When + testH.add(card1); + testH.add(card2); + int expected = 12; + int actual = blackJack.getTotal(testH); + + //Then + Assert.assertEquals(expected,actual); + + } + + @Test + public void testCheckHandTwentyOneFirst() { + //Given + BlackJack blackJack = new BlackJack(); + List testHand = new ArrayList(); + Card card1 = new Card(Suit.DIAMONDS, Rank.QUEEN); + Card card2 = new Card(Suit.SPADES, Rank.ACE); + + //When + testHand.add(card1); + testHand.add(card2); + int expected = 21; + int actual = blackJack.getTotal(testHand); + + //Then + + Assert.assertEquals(expected,actual); + } + + @Test + + public void testCheckHandTwentyOneSecond () { + //Given + BlackJack blackJack = new BlackJack(); + List testHand = new ArrayList(); + Card card1 = new Card(Suit.DIAMONDS, Rank.QUEEN); + Card card2 = new Card(Suit.SPADES, Rank.TWO); + Card card3 = new Card(Suit.HEARTS, Rank.EIGHT); + Card card4 = new Card(Suit.CLUBS, Rank.ACE); + //When + testHand.add(card1); + testHand.add(card2); + testHand.add(card3); + testHand.add(card4); + int expected = 21; + int actual = blackJack.getTotal(testHand); + + //Then + Assert.assertEquals(expected,actual); + } + @Test + + public void testCheckHandTwentyOneThird () { + //Given + BlackJack blackJack = new BlackJack(); + List testHand = new ArrayList(); + + Card card1 = new Card(Suit.DIAMONDS, Rank.QUEEN); + Card card2 = new Card(Suit.SPADES, Rank.TWO); + Card card3 = new Card(Suit.HEARTS, Rank.EIGHT); + Card card4 = new Card(Suit.CLUBS, Rank.ACE); + //When + testHand.add(card1); + testHand.add(card2); + testHand.add(card3); + testHand.add(card4); + + int total = blackJack.getTotal(testHand); + blackJack.setUserTotal(total); + + //Assert.assertTrue(blackJack.checkIfHandIs21()); + } + @Test + public void testCheckHandTwentyOneFourth () { + //Given + BlackJack blackJack = new BlackJack(); + List testHand = new ArrayList(); + + Card card1 = new Card(Suit.DIAMONDS, Rank.QUEEN); + Card card2 = new Card(Suit.SPADES, Rank.TWO); + Card card3 = new Card(Suit.HEARTS, Rank.EIGHT); + + //When + testHand.add(card1); + testHand.add(card2); + testHand.add(card3); + + int total = blackJack.getTotal(testHand); + blackJack.setUserTotal(total); + + // Assert.assertFalse(blackJack.checkIfHandIs21()); + } + + @Test + public void testCheckIfUserBustTrue() { + //Given + BlackJack blackJack = new BlackJack(); + List testHand = new ArrayList(); + + Card card1 = new Card(Suit.DIAMONDS, Rank.QUEEN); + Card card2 = new Card(Suit.SPADES, Rank.TWO); + Card card3 = new Card(Suit.HEARTS, Rank.EIGHT); + Card card4 = new Card(Suit.DIAMONDS, Rank.QUEEN); + + //When + testHand.add(card1); + testHand.add(card2); + testHand.add(card3); + testHand.add(card4); + + int total = blackJack.getTotal(testHand); + blackJack.setUserTotal(total); + + Assert.assertTrue(blackJack.checkGameOverByBust()); + } + + + @Test + public void testCheckIfUserBustFalse() { + //Given + BlackJack blackJack = new BlackJack(); + List testHand = new ArrayList(); + + Card card1 = new Card(Suit.DIAMONDS, Rank.QUEEN); + Card card2 = new Card(Suit.SPADES, Rank.TWO); + Card card3 = new Card(Suit.HEARTS, Rank.EIGHT); + Card card4 = new Card(Suit.DIAMONDS, Rank.ACE); + + //When + testHand.add(card1); + testHand.add(card2); + testHand.add(card3); + testHand.add(card4); + + int total = blackJack.getTotal(testHand); + blackJack.setUserTotal(total); + + Assert.assertFalse(blackJack.checkGameOverByBust()); + } + + @Test + public void displayDealerHandTest() { + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(null, baos); + BlackJack blackJack = new BlackJack(console); + List hand = new ArrayList<>(); + Card card1 = new Card(Suit.DIAMONDS, Rank.TEN); + Card card2 = new Card(Suit.HEARTS, Rank.SEVEN); + + //When + hand.add(card1); + hand.add(card2); + blackJack.getDealer().setHand(hand); + blackJack.displayDealerHand(); + String expected = "Dealer's hand is now: \n" + + "10━━┓7━━━┓\n" + + "┃ ┃┃ ┃\n" + + "┃ ♢ ┃┃ ♡ ┃\n" + + "┃ ┃┃ ┃\n" + + "┗━━10┗━━━7\n" + + "\n"; + + //Then + Assert.assertEquals(expected, baos.toString()); + } + @Test + public void displayDealerFirstHandTest() { + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(null, baos); + BlackJack blackJack = new BlackJack(console); + List hand = new ArrayList<>(); + Card card1 = new Card(Suit.DIAMONDS, Rank.EIGHT); + Card card2 = new Card(Suit.HEARTS, Rank.SEVEN); + + //When + hand.add(card1); + hand.add(card2); + blackJack.getDealer().setHand(hand); + blackJack.displayDealersFirstHand(); + String expected = "Dealer's hand is showing: \n" + + "8━━━┓┏━━━┓\n" + + "┃ ┃┃Ƞ ┃\n" + + "┃ ♢ ┃┃ Ʉ ┃\n" + + "┃ ┃┃ ʗ┃\n" + + "┗━━━8┗━━━┛\n" + + "\n"; + + //Then + Assert.assertEquals(expected, baos.toString()); + } + + @Test + + public void checkUserInputTestHit(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("hit", baos); + BlackJack blackJack = new BlackJack(console); + + //When + String black = blackJack.getUserInput(); + String expected = "hit"; + + //Then + Assert.assertTrue(baos.toString().contains("Would you like to Hit or Stay?")); + Assert.assertEquals(expected, black); + + } + + @Test + + public void checkUserInputTestStay(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("stay", baos); + BlackJack blackJack = new BlackJack(console); + + //When + String black = blackJack.getUserInput(); + String expected = "stay"; + + //Then + Assert.assertTrue(baos.toString().contains("Would you like to Hit or Stay?")); + Assert.assertEquals(expected, black); + + } + @Test + public void testEvaluateUserHitOrStayInvalidInput(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("stjjay", baos); + BlackJack blackJack = new BlackJack(console); + + //When + blackJack.evaluateUserHitOrStay(); + + //Then + Assert.assertTrue(baos.toString().contains("Please enter a valid option of Hit or Stay")); + + } + @Test + public void testEvaluateUserHitOrStay_Stay(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("100\nstay", baos); + BlackJack blackJack = new BlackJack(console); + List hand = new ArrayList<>(); + Card card1 = new Card(Suit.DIAMONDS, Rank.EIGHT); + Card card2 = new Card(Suit.HEARTS, Rank.SEVEN); + + blackJack.getUser().setBalance(1000); + blackJack.setUserTotal(100); + + //When + hand.add(card1); + hand.add(card2); + + blackJack.getUser().setHand(hand); + blackJack.getDealer().setHand(hand); + blackJack.getUserBet(); + + //When + blackJack.evaluateUserHitOrStay(); + + //Then + Assert.assertTrue(baos.toString().contains("Dealer card is: \n")); + } + @Test + public void testEvaluateUserHitOrStay_Hit(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("100\nhit", baos); + BlackJack blackJack = new BlackJack(console); + List hand = new ArrayList<>(); + Card card1 = new Card(Suit.DIAMONDS, Rank.EIGHT); + Card card2 = new Card(Suit.HEARTS, Rank.SEVEN); + + blackJack.getUser().setBalance(1000); + blackJack.setUserTotal(100); + + //When + hand.add(card1); + hand.add(card2); + + blackJack.getUser().setHand(hand); + blackJack.getDealer().setHand(hand); + blackJack.getUserBet(); + + //When + blackJack.evaluateUserHitOrStay(); + + //Then + Assert.assertTrue(baos.toString().contains("Your next card is \n")); + } + + @Test + public void checkHitTest1(){ + + //Given + BlackJack blackJack = new BlackJack(); + List hand = new ArrayList(); + Card c = new Card(Suit.HEARTS, Rank.ACE); + hand.add(c); + hand.add(c); + blackJack.getUser().setHand(hand); + + //When + blackJack.hit(); + + //Then + Assert.assertTrue(hand.size() == 3); + } + + @Test + public void displayUserTotalTest(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(null, baos); + BlackJack blackJack = new BlackJack(console); + + //When + userTotal = 19; + blackJack.displayUserTotal(userTotal); + String expected = "Your total is 19\n"; + + //Then + Assert.assertEquals(expected,baos.toString()); + } + + @Test + public void displayDealerTotalTest() { + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(null, baos); + BlackJack blackJack = new BlackJack(console); + + //When + dealerTotal = 21; + blackJack.displayDealerTotal(dealerTotal); + String expected = "Dealer total is 21\n"; + + //Then + Assert.assertEquals(expected,baos.toString()); + } + @Test + public void displayUserBalanceTest(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(null, baos); + BlackJack blackJack = new BlackJack(console); + + //When + blackJack.getUser().setBalance(21); + blackJack.displayUserBalance(); + String expected = "Your balance is: $21\n"; + + //Then + Assert.assertEquals(expected,baos.toString()); + } + + @Test + public void testCelebrateUser(){ + //Given + String input = "10\n"; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(input, baos); + BlackJack blackJack = new BlackJack(console); + + + //When + blackJack.getUser().setBalance(100); + blackJack.getUserBet(); + + blackJack.celebrateUser(); + + //Then + Assert.assertTrue(baos.toString().contains("You are the Winner!!!!")); + } + @Test + public void testCheckIfUserWantsToDoubleDownInvalidInput(){ + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("doubbb\nyes", baos); + BlackJack blackJack = new BlackJack(console); + List hand = new ArrayList<>(); + Card card1 = new Card(Suit.DIAMONDS, Rank.EIGHT); + Card card2 = new Card(Suit.HEARTS, Rank.SEVEN); + + blackJack.getUser().setBalance(1000); + blackJack.setUserTotal(100); + hand.add(card1); + hand.add(card2); + + blackJack.getUser().setHand(hand); + blackJack.getDealer().setHand(hand); + + //When + blackJack.setUserBet(10); + blackJack.checkIfUserWantsToDoubleDown(); + + //Then + Assert.assertTrue(baos.toString().contains("Please enter a valid option of Yes or No")); + } + @Test + public void testCheckIfUserWantsToDoubleDownYes() { + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("YES\n", baos); + BlackJack blackJack = new BlackJack(console); + List hand = new ArrayList<>(); + Card card1 = new Card(Suit.DIAMONDS, Rank.EIGHT); + Card card2 = new Card(Suit.HEARTS, Rank.SEVEN); + + blackJack.getUser().setBalance(1000); + blackJack.setUserTotal(10); + hand.add(card1); + hand.add(card2); + + blackJack.getUser().setHand(hand); + blackJack.getDealer().setHand(hand); + + //When + blackJack.setUserBet(20); + blackJack.checkIfUserWantsToDoubleDown(); + System.out.println(baos.toString()); + + //Then + Assert.assertTrue(baos.toString().contains("Your balance is: $980")); + } + @Test + public void testCheckIfUserWantsToDoubleDownYesInsufficientFunds() { + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("YES\n", baos); + BlackJack blackJack = new BlackJack(console); + List hand = new ArrayList<>(); + Card card1 = new Card(Suit.DIAMONDS, Rank.EIGHT); + Card card2 = new Card(Suit.HEARTS, Rank.SEVEN); + + blackJack.getUser().setBalance(1000); + blackJack.setUserTotal(10); + hand.add(card1); + hand.add(card2); + + blackJack.getUser().setHand(hand); + blackJack.getDealer().setHand(hand); + + //When + blackJack.setUserBet(2000); + blackJack.checkIfUserWantsToDoubleDown(); + System.out.println(baos.toString()); + + //Then + Assert.assertTrue(baos.toString().contains("Your broke ass has insufficient funds..")); + } + + @Test + public void testCheckIfUserWantsToDoubleDownNo() { + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput("no", baos); + BlackJack blackJack = new BlackJack(console); + List hand = new ArrayList<>(); + Card card1 = new Card(Suit.DIAMONDS, Rank.EIGHT); + Card card2 = new Card(Suit.HEARTS, Rank.SEVEN); + + blackJack.getUser().setBalance(1000); + blackJack.setUserTotal(10); + hand.add(card1); + hand.add(card2); + + blackJack.getUser().setHand(hand); + blackJack.getDealer().setHand(hand); + + //When + blackJack.setUserBet(20); + blackJack.checkIfUserWantsToDoubleDown(); + + //Then + Assert.assertTrue(baos.toString().contains("Would you like to Double Down? Please enter Yes or No")); + } + + @Test + public void testCheckWinnerDealerBustTest() { + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(null, baos); + BlackJack blackJack = new BlackJack(console); + + //When + dealerTotal = 22; + userTotal = 20; + blackJack.setUserBet(20); + blackJack.getUser().setBalance(100); + blackJack.setUserTotal(userTotal); + blackJack.setDealerTotal(dealerTotal); + blackJack.checkWinner(); + + //Then + Assert.assertTrue(baos.toString().contains("Dealer Busts.")); + } + + @Test + public void testCheckWinnerPush() { + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(null, baos); + BlackJack blackJack = new BlackJack(console); + + //When + dealerTotal = 12; + userTotal = 12; + + blackJack.setUserBet(20); + + blackJack.getUser().setBalance(100); + blackJack.setUserTotal(userTotal); + blackJack.setDealerTotal(dealerTotal); + blackJack.checkWinner(); + + //Then + System.out.println(baos.toString()); + Assert.assertTrue(baos.toString().contains("It's a Push. Ehh")); + } + @Test + public void testCheckWinnerDealerWins() { + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(null, baos); + BlackJack blackJack = new BlackJack(console); + + //When + dealerTotal = 12; + userTotal = 10; + + blackJack.setUserBet(20); + + blackJack.getUser().setBalance(100); + blackJack.setUserTotal(userTotal); + blackJack.setDealerTotal(dealerTotal); + blackJack.checkWinner(); + + //Then + System.out.println(baos.toString()); + Assert.assertTrue(baos.toString().contains("Dealer is the winner")); + } + @Test + public void testCheckWinnerUserWins() { + //Given + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Console console = getConsoleWithBufferedInputAndOutput(null, baos); + BlackJack blackJack = new BlackJack(console); + + //When + dealerTotal = 12; + userTotal = 14; + + blackJack.setUserBet(20); + + blackJack.getUser().setBalance(100); + blackJack.setUserTotal(userTotal); + blackJack.setDealerTotal(dealerTotal); + blackJack.checkWinner(); + + //Then + System.out.println(baos.toString()); + Assert.assertTrue(baos.toString().contains("You are the winner")); + } + + public Console getConsoleWithBufferedInputAndOutput(String input, ByteArrayOutputStream baos){ + Console testConsole; + if (input == null) { + testConsole = new Console(System.in, new PrintStream(baos)); + } else { + ByteArrayInputStream bais = new ByteArrayInputStream(input.getBytes()); + testConsole = new Console(bais, new PrintStream(baos)); + } + + return testConsole; + } + + + +} + + + + + + + diff --git a/src/test/java/io/zipcoder/casino/casino/GameTest/CardTest.java b/src/test/java/io/zipcoder/casino/casino/GameTest/CardTest.java new file mode 100644 index 000000000..944795ba2 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/GameTest/CardTest.java @@ -0,0 +1,65 @@ +package io.zipcoder.casino.casino.GameTest; + +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Card; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Deck; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Rank; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Suit; +import org.junit.Assert; +import org.junit.Test; + +public class CardTest { + + @Test + + public void testCardConstructor() { + //Given + Rank rank = Rank.ACE; + Suit suit = Suit.DIAMONDS; + Card testCard = new Card(suit,rank); + + //When + Rank actualRank = testCard.getRank(); + Suit actualSuit = testCard.getSuit(); + + //Then + Assert.assertEquals(rank,actualRank); + Assert.assertEquals(suit,actualSuit); + + } + + @Test + public void testCardSetMethod() { + //Given + Rank rank = Rank.FIVE; + Suit suit = Suit.SPADES; + Card testCard = new Card(suit,rank); + + //When + Rank actualRank = testCard.getRank(); + Suit actualSuit = testCard.getSuit(); + String expected = rank.toString().toLowerCase() + " of "+suit.toString().toLowerCase(); + //Then + Assert.assertEquals(expected,testCard.toString()); + Assert.assertEquals(suit,actualSuit); + + } + @Test + public void testGetCardBack() { + //Given + Card testCard = Deck.getCardBack(); + + //When + String actualBack = Card.printAllCards(testCard); + String expected = + "┏━━━┓\n" + + "┃Ƞ ┃\n" + + "┃ Ʉ ┃\n" + + "┃ ʗ┃\n" + + "┗━━━┛\n"; + //Then + Assert.assertEquals(expected, actualBack); + + } + + +} diff --git a/src/test/java/io/zipcoder/casino/casino/GameTest/CrapsTest.java b/src/test/java/io/zipcoder/casino/casino/GameTest/CrapsTest.java new file mode 100644 index 000000000..9158d2ea8 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/GameTest/CrapsTest.java @@ -0,0 +1,899 @@ +package io.zipcoder.casino.casino.GameTest; + +import io.zipcoder.casino.casino.games.dicegames.diceutilities.Dice; +import io.zipcoder.casino.casino.games.dicegames.diceutilities.LoadedDice; +import io.zipcoder.casino.casino.games.dicegames.Craps; +import io.zipcoder.casino.casino.utilities.Console; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.List; +import java.util.Map; +import java.util.Scanner; + +public class CrapsTest { + private ByteArrayInputStream byteStream; + private ByteArrayOutputStream outputStream; + private Console testConsole;//new PrintStream(outputStream)); + private Craps craps; + + private Craps helperFunction(String input) { + String userInput = input; + byteStream = new ByteArrayInputStream(userInput.getBytes()); + outputStream = new ByteArrayOutputStream(); + testConsole = new Console(new Scanner(byteStream), new PrintStream(outputStream)); + craps = new Craps(testConsole); + return craps; + } + + private Craps helperFunctionNoInput() { + outputStream = new ByteArrayOutputStream(); + testConsole = new Console(System.in, new PrintStream(outputStream)); + craps = new Craps(testConsole); + return craps; + } + + @Test + public void promptBetTest1() { + // Given + Craps craps = helperFunction("50\npass"); + craps.setIsFirstRoll(true); + + // When + craps.promptBet(); + // boolean toWinPassBet = craps.getToWinPassBet(); + Map betMap = craps.getBetMap(); + + // Then +// Assert.assertTrue(toWinPassBet); + Assert.assertTrue(betMap.get("Pass Bet")); + } + + @Test + public void promptBetTest2() { + // Given + Craps craps = helperFunction("100\nDon't pass"); + craps.setIsFirstRoll(true); + + // When + craps.promptBet(); + craps.setBetInBetMap("Pass Bet", false); + + // Then + Assert.assertFalse(craps.getBetInBetMap("Pass Bet")); + } + + @Test + public void promptBetTest3() { + // Given + Craps craps = helperFunction("2\n5"); + craps.setIsFirstRoll(false); + craps.clearBets(); + craps.setBetInBetMap("Pass Bet", true); + String expectedOutput = "You have five choices:\n" + + "1) Explain Possible Bets\n" + + "2) List Current Bets\n" + + "3) List Available Bets\n" + + "4) Make a Bet\n" + + "5) Continue Rolling\n" + + "You have the current bets: [Pass Bet]\n" + + "\n" + + "You have five choices:\n" + + "1) Explain Possible Bets\n" + + "2) List Current Bets\n" + + "3) List Available Bets\n" + + "4) Make a Bet\n" + + "5) Continue Rolling"; + + // When + craps.promptBet(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + } + + @Test + public void betRulesListedTest() { + // Given + Craps craps = helperFunctionNoInput(); + String expectedOutput = "The Place bet wins if the chosen number is rolled before a 7\n" + + "The Lay bet wins if a 7 is rolled before the point\n" + + "Any Craps pays off on 2, 3 or 12 before rolling a 7\n" + + "The Field wins if 4, 5, 6, 8, 9 or 10 hits before 7\n" + + "The Horn wins on 2, 3, 11 or 12 before rolling a 7\n" + + "Hardways involves two dice of the same face value, which must be hit before 7 or the corresponding sum thrown 'easy'"; + + // When + craps.betRulesListed(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + } + + @Test + public void setBetInBetMapTest() { + // Given + Craps craps = new Craps(); + + // When + craps.setBetInBetMap("Pass Bet", true); + boolean retrieved = craps.getBetInBetMap("Pass Bet"); + + // Then + Assert.assertTrue(retrieved); + } + + @Test + public void currentBetListTest() { + // Given + Craps craps = new Craps(); + craps.setBetInBetMap("Place Bet", true); + craps.setBetInBetMap("Lay Bet", true); + craps.setBetInBetMap("Hardways", true); + // When + List actualBets = craps.currentBetList(true); + + // Then + Assert.assertTrue(actualBets.contains("Place Bet")); + Assert.assertTrue(actualBets.contains("Lay Bet")); + Assert.assertTrue(actualBets.contains("Hardways")); + } + + /*@Test + public void evaluateFirstRollTest1() { + // Given + Craps craps = helperFunctionNoInput(); + craps.setRollSum(2); + craps.setBetInBetMap("Pass Bet", true); + String expectedOutput = "You lost your bet!\n" + + "\n" + + "-50 NUCs gone already? Play again to win that back and more!"; + craps.setBetAmount(50); + int initialAdjustedBalance = craps.getAdjustedBalance(); + int expectedAdjustment = -50; + + // When + craps.evaluateFirstRoll(); + String actualOutput = outputStream.toString().trim(); + int actualAdjustment = craps.getAdjustedBalance() - initialAdjustedBalance; + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + Assert.assertEquals(expectedAdjustment, actualAdjustment); + } + + @Test + public void evaluateFirstRollTest2() { + // Given + Craps craps = helperFunctionNoInput(); + craps.setRollSum(7); + craps.setBetInBetMap("Pass Bet", true); + String expectedOutput = "Your bet paid off!\n" + + "\n" + + "You're on a roll and 50 NUCs richer!"; + craps.setBetAmount(50); + int initialAdjustedBalance = craps.getAdjustedBalance(); + int expectedAdjustment = 50; + + // When + craps.evaluateFirstRoll(); + String actualOutput = outputStream.toString().trim(); + int actualAdjustment = craps.getAdjustedBalance() - initialAdjustedBalance; + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + Assert.assertEquals(expectedAdjustment, actualAdjustment); + } + + @Test + public void evaluateFirstRollTest3() { + // Given + Craps craps = helperFunctionNoInput(); + craps.setRollSum(7); + craps.setBetInBetMap("Pass Bet", false); + String expectedOutput = "You lost your bet!\n" + + "\n" + + "-50 NUCs gone already? Play again to win that back and more!"; + craps.setBetAmount(50); + int initialAdjustedBalance = craps.getAdjustedBalance(); + int expectedAdjustment = -50; + + // When + craps.evaluateFirstRoll(); + String actualOutput = outputStream.toString().trim(); + int actualAdjustment = craps.getAdjustedBalance() - initialAdjustedBalance; + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + Assert.assertEquals(expectedAdjustment, actualAdjustment); + } + + @Test + public void evaluateFirstRollTest4() { + // Given + Craps craps = helperFunctionNoInput(); + craps.setRollSum(2); + craps.setBetInBetMap("Pass Bet", false); + String expectedOutput = "You lost your bet!\n" + + "\n" + + "You're on a roll and 50 NUCs richer!"; + craps.setBetAmount(50); + int initialAdjustedBalance = craps.getAdjustedBalance(); + int expectedAdjustment = 50; + + // When + craps.evaluateFirstRoll(); + String actualOutput = outputStream.toString().trim(); + int actualAdjustment = craps.getAdjustedBalance() - initialAdjustedBalance; + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + Assert.assertEquals(expectedAdjustment, actualAdjustment); + } +*/ + @Test + public void evaluateFirstRollTest5() { + // Given + Craps craps = helperFunctionNoInput(); + craps.setRollSum(5); + int expectedPoint = 5; + String expectedOutput = "The point is now 5."; + + // When + craps.evaluateFirstRoll(); + String actualOutput = outputStream.toString().trim(); + int actualPoint = craps.getPoint(); + boolean isFirstRoll = craps.getIsFirstRoll(); + + // Then + Assert.assertEquals(expectedPoint, actualPoint); + Assert.assertEquals(expectedOutput, actualOutput); + Assert.assertFalse(isFirstRoll); + } + + @Test + public void resetPointAndRollTest() { + // Given + Craps craps = new Craps(); + craps.setPoint(5); + craps.setIsFirstRoll(false); + int expectedPoint = 0; + + // When + craps.resetPointAndRoll(); + int actualPoint = craps.getPoint(); + + // Then + Assert.assertTrue(craps.getIsFirstRoll()); + Assert.assertEquals(expectedPoint, actualPoint); + } + + @Test + public void filteredBetListTest() { + // Given + Craps craps = helperFunctionNoInput(); + String betOptions = "always"; + String expectedOutput = "PLACE\n" + + "LAY\n" + + "HARDWAYS"; + + // When + craps.filteredBetList(betOptions); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + } + + @Test + public void listBetsTest() { + // Given + Craps craps = helperFunction("2"); + String expectedOutput = "Choose one of the follow:\n" + + "1) List Bets always available\n" + + "2) List one-off Bets\n" + + "3) Go to previous Menu\n" + + "ANYCRAPS\n" + + "FIELD\n" + + "HORN"; + + // When + craps.listBets(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + + } + + @Test + public void makeBetTest1() { + // Given + Craps craps = helperFunction("place\n6"); + String expectedOutput = "What bet would you like to place?" + + "\n" + + "What number do you want to make a Place Bet for?" + + "\n" + + "Excellent choice!"; + craps.setBetInBetMap("Place Bet", false); + + // When + craps.makeBet(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + Assert.assertTrue(craps.getBetInBetMap("Place Bet")); + } + + @Test + public void makeBetTest2() { + // Given + Craps craps = helperFunction("place\n7\n5"); + String expectedOutput = "What bet would you like to place?\n" + + "What number do you want to make a Place Bet for?\n" + + "Stick to the Place numbers, buddy! Pick from 4, 5, 6, 8, 9 or 10"; + craps.setBetInBetMap("Place Bet", false); + + // When + craps.makeBet(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + Assert.assertTrue(craps.getBetInBetMap("Place Bet")); + } + + @Test + public void makeBetTest3() { + // Given + Craps craps = helperFunction("lay"); + craps.setBetInBetMap("Lay Bet", false); + + // When + craps.makeBet(); + + // Then + Assert.assertTrue(craps.getBetInBetMap("Lay Bet")); + } + + @Test + public void makeBetTest4() { + // Given + Craps craps = helperFunction("anycraps"); + craps.setBetInBetMap("Any Craps", false); + + // When + craps.makeBet(); + + // Then + Assert.assertTrue(craps.getBetInBetMap("Any Craps")); + } + + @Test + public void makeBetTest5() { + // Given + Craps craps = helperFunction("hardways\n10"); + craps.setBetInBetMap("Hardways", false); + String expectedOutput = "What bet would you like to place?\n" + + "What number do you want to place a Hardways Bet on?\n" + + "Excellent choice!"; + + // When + craps.makeBet(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertTrue(craps.getBetInBetMap("Hardways")); + Assert.assertEquals(expectedOutput, actualOutput); + } + + @Test + public void makeBetTest6() { + // Given + Craps craps = helperFunction("hardways\n2\n8"); + craps.setBetInBetMap("Hardways", false); + String expectedOutput = "What bet would you like to place?\n" + + "What number do you want to place a Hardways Bet on?\n" + + "Stick to the Place numbers, buddy! Pick from 4, 6, 8, or 10"; + + // When + craps.makeBet(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertTrue(craps.getBetInBetMap("Hardways")); + Assert.assertEquals(expectedOutput, actualOutput); + } + + @Test + public void makeBetTest7() { + // Given + Craps craps = helperFunction("doubledown\nanycraps"); + String expectedOutput = "What bet would you like to place?\n" + + "Please enter an actual bet, pal\n" + + "What bet would you like to place?"; + + // When + craps.makeBet(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + } + + @Test + public void rollTest1() { + // Given + Craps craps = helperFunctionNoInput(); + Dice diceRoll2 = new LoadedDice(2); + craps.setDie1(diceRoll2); + craps.setDie2(diceRoll2); + craps.setRollSum(0); + craps.setRollSumHardways(false); + int expectedRollSum = 4; + String expectedOutput = "HERE ARE YOUR DIE:\n" + + "┏━━━━━━━━┓┏━━━━━━━━┓\n" + + "┃ ⬤ ┃┃ ⬤ ┃\n" + + "┃ ┃┃ ┃\n" + + "┃ ⬤ ┃┃ ⬤ ┃\n" + + "┗━━━━━━━━┛┗━━━━━━━━┛"; + int expectedReturn = expectedRollSum; + + + // When + int actualReturn = craps.roll(); + int actualRollSum = craps.getRollSum(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedRollSum, actualRollSum); + Assert.assertTrue(craps.getRollSumHardways()); + Assert.assertEquals(expectedOutput, actualOutput); + Assert.assertEquals(expectedReturn, actualReturn); + } + + @Test + public void rollTest2() { + // Given + Craps craps = helperFunctionNoInput(); + Dice diceRoll5 = new LoadedDice(5); + Dice diceRoll2 = new LoadedDice(2); + craps.setDie1(diceRoll5); + craps.setDie2(diceRoll2); + craps.setRollSum(0); + craps.setRollSumHardways(true); + int expectedRollSum = 7; + String expectedOutput = "HERE ARE YOUR DIE:"; + int expectedReturn = expectedRollSum; + + // When + int actualReturn = craps.roll(); + int actualRollSum = craps.getRollSum(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedRollSum, actualRollSum); + Assert.assertFalse(craps.getRollSumHardways()); + Assert.assertTrue(actualOutput.contains(expectedOutput)); + Assert.assertEquals(expectedReturn, actualReturn); + } + + public static void main(String[] args) + { + /* Craps craps = new Craps(); + craps.setBetInBetMap("Lay Bet", true); + craps.setBetAmount(100); + int expectedTotalBalance = craps.getAdjustedBalance() + craps.getBetAmount(); + String expectedOutput = "Your Lay bet paid off!\n" + + "\n" + + "You're on a roll and 100 NUCs richer!"; + + // When + craps.evaluate(); + + // Then*/ + } + + /*@Test + public void evaluateTest1() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setBetInBetMap("Lay Bet", true); + craps.setBetAmount(100); + int expectedTotalBalance = craps.getAdjustedBalance() + craps.getBetAmount(); + String expectedOutput = "Your bet paid off!\n" + + "\n" + + "You're on a roll and 100 NUCs richer!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + + Assert.assertTrue(actualOutput.contains(expectedOutput)); + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + } + + @Test + public void evaluateTest2() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setBetInBetMap("Lay Bet", false); + craps.setBetInBetMap("Pass Bet", false); + craps.setBetAmount(100); + int expectedTotalBalance = craps.getAdjustedBalance() + craps.getBetAmount(); + String expectedOutput = "Your bet paid off!\n" + + "\n" + + "You're on a roll and 100 NUCs richer!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + + Assert.assertTrue( actualOutput.contains(expectedOutput)); + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + } + + @Test + public void evaluateTest3() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setBetInBetMap("Lay Bet", false); + craps.setBetInBetMap("Pass Bet", true); + craps.setBetAmount(100); + int expectedTotalBalance = craps.getAdjustedBalance() - craps.getBetAmount(); + String expectedOutput = "Sorry shooter, it looks like your hot streak has come to an end!\n" + + "\n" + + "-100 NUCs gone already? Play again to win that back and more!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + + Assert.assertTrue(actualOutput.contains(expectedOutput)); + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + } + + @Test + public void evaluateTest4() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setIsFirstRoll(false); + craps.setBetInBetMap("Any Craps", true); + craps.setRollSum(2); + craps.setBetAmount(50); + int expectedTotalBalance = craps.getAdjustedBalance() + craps.getBetAmount(); + String expectedOutput = "Your bet paid off!\n" + + "\n" + + "You're on a roll and 50 NUCs richer!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertTrue(actualOutput.contains(expectedOutput)); + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + } + + @Test + public void evaluateTest5() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setIsFirstRoll(false); + craps.setBetInBetMap("Any Craps", true); + craps.setRollSum(5); + craps.setBetAmount(50); + int expectedTotalBalance = craps.getAdjustedBalance() - craps.getBetAmount(); + String expectedOutput = "You lost your bet!\n" + + "\n" + + "-50 NUCs gone already? Play again to win that back and more!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertTrue(actualOutput.contains(expectedOutput)); + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + } + + @Test + public void evaluateTest6() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setBetInBetMap("The Field", true); + craps.setRollSum(3); + craps.setBetAmount(80); + int expectedTotalBalance = craps.getAdjustedBalance() + 80; + String expectedOutput = "You won your Field bet!\n" + + "\n" + + "You're on a roll and 80 NUCs richer!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + Assert.assertTrue(actualOutput.contains(expectedOutput)); + } + + @Test + public void evaluateTest7() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setBetInBetMap("The Field", false); + craps.setBetInBetMap("The Horn", true); + craps.setRollSum(2); + craps.setBetAmount(80); + int expectedTotalBalance = craps.getAdjustedBalance() + 80; + String expectedOutput = "Your bet paid off!\n" + + "\n" + + "You're on a roll and 80 NUCs richer!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + Assert.assertTrue(actualOutput.contains(expectedOutput)); + } + + @Test + public void evaluateTest8() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setBetInBetMap("The Field", false); + craps.setBetInBetMap("The Horn", false); + craps.setBetInBetMap("Hardways", true); + craps.setHardwaysRoll(4); + craps.setRollSum(4); + craps.setBetAmount(80); + craps.setAdjustedBalance(100); + int expectedTotalBalance = craps.getAdjustedBalance() + 80; + String expectedOutput = "Your bet paid off!\n" + + "\n" + + "You're on a roll and 80 NUCs richer!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + Assert.assertTrue(actualOutput.contains(expectedOutput)); + } + + @Test + public void evaluateTest9() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setBetInBetMap("The Field", false); + craps.setBetInBetMap("The Horn", false); + craps.setBetInBetMap("Hardways", false); + craps.setBetInBetMap("Lay Bet", true); + craps.setRollSum(7); + craps.setBetAmount(80); + craps.setAdjustedBalance(100); + int expectedTotalBalance = craps.getAdjustedBalance() + 80; + String expectedOutput = "Your bet paid off!\n" + + "\n" + + "You're on a roll and 80 NUCs richer!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + Assert.assertTrue(actualOutput.contains(expectedOutput)); + } + + @Test + public void evaluateTest10() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setBetInBetMap("The Field", false); + craps.setBetInBetMap("The Horn", false); + craps.setBetInBetMap("Hardways", false); + craps.setBetInBetMap("Lay Bet", false); + craps.setPoint(4); + craps.setRollSum(4); + craps.setBetInBetMap("Pass Bet", true); + craps.setBetAmount(80); + craps.setAdjustedBalance(100); + int expectedTotalBalance = craps.getAdjustedBalance() + 80; + String expectedOutput = "Lucky number 4! You hit the point!\n" + + "\n" + + "You're on a roll and 80 NUCs richer!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + Assert.assertTrue(actualOutput.contains(expectedOutput)); + } +*/ + @Test + public void evaluateTest11() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setBetInBetMap("The Field", false); + craps.setBetInBetMap("The Horn", false); + craps.setBetInBetMap("Hardways", false); + craps.setBetInBetMap("Lay Bet", false); + craps.setPoint(4); + craps.setRollSum(5); + + // When + craps.evaluate(); + + // Then + } + + /* @Test + public void evaluateTest12() { + // Given + Craps craps = helperFunction("yes\nno"); + craps.setBetInBetMap("The Field", false); + craps.setBetInBetMap("The Horn", false); + craps.setBetInBetMap("Hardways", false); + craps.setBetInBetMap("Lay Bet", true); + craps.setPlaceBetChoice(5); + craps.setRollSum(5); + craps.setBetAmount(80); + craps.setAdjustedBalance(100); + int expectedTotalBalance = craps.getAdjustedBalance() + 80; + String expectedOutput = "Your bet paid off!\n" + + "\n" + + "You're on a roll and 80 NUCs richer!"; + + // When + craps.evaluate(); + int actualTotalBalance = craps.getAdjustedBalance(); + String actualOutput = outputStream.toString().trim(); + + // Then + Assert.assertTrue(actualOutput.contains(expectedOutput)); + Assert.assertEquals(expectedTotalBalance, actualTotalBalance); + }*/ + + @Test + public void adjustBalanceTest() { + // Given + Craps craps = helperFunctionNoInput(); + craps.setAdjustedBalance(300); + craps.setBetAmount(100); + int expected = 400; + + // When + craps.adjustBalance(craps.getBetAmount()); + int actual = craps.getAdjustedBalance(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void promptQuitTest() { + // Given + Craps craps = helperFunction("no"); + String expected = "Would you like to quit while you're ahead?\n" + + "Okay, you're a responsible adult, and you know your limits"; + + // When + craps.promptQuit(); + String actual = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void cashOutTest1() { + // Given + Craps craps = helperFunction("no"); + int usersInitialBalance = craps.getUser().getProfile().getBalance(); + craps.setInitialBalance(usersInitialBalance); + craps.setAdjustedBalance(usersInitialBalance + 400); + String expectedOutput = "Wouldn't you rather continue playing?\n" + + "You won 400 NUCs!"; + int expectedUserBalance = usersInitialBalance + 400; + + // When + craps.cashOut(); + String actualOutput = outputStream.toString().trim(); + int actualUserBalance = craps.getUser().getProfile().getBalance(); + + // Then + Assert.assertEquals(expectedOutput, actualOutput); + Assert.assertEquals(expectedUserBalance, actualUserBalance); + } + + @Test + public void cashOutTest2() { + // Given + Craps craps = helperFunction("yes"); + String expected = "Wouldn't you rather continue playing?"; + + // When + craps.cashOut(); + String actual = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void compareBalanceTest1() { + // Given + Craps craps = helperFunctionNoInput(); + craps.setAdjustedBalance(200); + craps.setInitialBalance(100); + String expected = "You won 100 NUCs!"; + + // When + craps.compareBalance(); + String actual = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void compareBalanceTest2() { + // Given + Craps craps = helperFunctionNoInput(); + craps.setAdjustedBalance(0); + craps.setInitialBalance(100); + String expected = "You're 100 NUCs poorer!"; + + // When + craps.compareBalance(); + String actual = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void compareBalanceTest3() { + // Given + Craps craps = helperFunctionNoInput(); + craps.setAdjustedBalance(100); + craps.setInitialBalance(100); + String expected = "You broke even!"; + + // When + craps.compareBalance(); + String actual = outputStream.toString().trim(); + + // Then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/casino/casino/GameTest/GoFishTest.java b/src/test/java/io/zipcoder/casino/casino/GameTest/GoFishTest.java new file mode 100644 index 000000000..b63ffc87e --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/GameTest/GoFishTest.java @@ -0,0 +1,580 @@ +package io.zipcoder.casino.casino.GameTest; + +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Card; +import io.zipcoder.casino.casino.games.cardgames.GoFish; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Rank; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Suit; +import io.zipcoder.casino.casino.utilities.Console; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.Collections; +import java.util.Scanner; + +public class GoFishTest { + + @Test + public void dealerTurnTest() { + // Given + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + GoFish goFish = new GoFish(console); + + // When + goFish.dealerTurn(); + String actual = outputStream.toString(); + + // Then + Assert.assertTrue(actual.contains("I'm out of cards in my hand! I'll just draw")); + } + + @Test + public void dealerTurnTest2() { + // Given + String input = "no"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish goFish = new GoFish(console); + Card testCard = new Card(Suit.HEARTS, Rank.THREE); + goFish.getDealer().addToHand(testCard); + goFish.getUser().addToHand(testCard); + goFish.getUser().addToHand(testCard); + + // When + goFish.dealerTurn(); + String actual = outputStream.toString(); + + // Then + int expectedNumberOfDealerCards = 3; + Assert.assertTrue(actual.contains("J'accuse!")); + Assert.assertEquals(expectedNumberOfDealerCards, goFish.getDealer().getHandSize()); + } + + @Test + public void tryForUserCardTest() { + // Given + String input = "no"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish goFish = new GoFish(console); + Card testCard = new Card(Suit.HEARTS, Rank.THREE); + goFish.getDealer().addToHand(testCard); + goFish.getUser().addToHand(testCard); + goFish.getUser().addToHand(testCard); + + // When + goFish.tryForUserCard(); + String actual = outputStream.toString(); + + // Then + int expectedNumberOfDealerCards = 3; + Assert.assertTrue(actual.contains("J'accuse!")); + Assert.assertEquals(expectedNumberOfDealerCards, goFish.getDealer().getHandSize()); + } + + @Test + public void tryForUserCardTest2() { + // Given + String input = "yes"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish goFish = new GoFish(console); + Card testCard = new Card(Suit.HEARTS, Rank.THREE); + goFish.getDealer().addToHand(testCard); + goFish.getUser().addToHand(testCard); + goFish.getUser().addToHand(testCard); + + // When + goFish.tryForUserCard(); + String actual = outputStream.toString(); + + // Then + int expectedNumberOfDealerCards = 3; + System.out.print(outputStream.toString()); + Assert.assertTrue(actual.contains("I'll take these:")); + Assert.assertEquals(expectedNumberOfDealerCards, goFish.getDealer().getHandSize()); + } + + @Test + public void tryForUserCardTest3() { + // Given + String input = "yes"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish goFish = new GoFish(console); + Card testCard = new Card(Suit.HEARTS, Rank.THREE); + goFish.getDealer().addToHand(testCard); + + // When + goFish.tryForUserCard(); + String actual = outputStream.toString(); + + // Then + int expectedNumberOfDealerCards = 2; + Assert.assertTrue(actual.contains("Huh, it doesn't actually look like you do.")); + Assert.assertEquals(expectedNumberOfDealerCards, goFish.getDealer().getHandSize()); + } + + @Test + public void tryForUserCardTest4() { + // Given + String input = "no"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish goFish = new GoFish(console); + Card testCard = new Card(Suit.HEARTS, Rank.THREE); + goFish.getDealer().addToHand(testCard); + + // When + goFish.tryForUserCard(); + + // Then + int expectedNumberOfDealerCards = 2; + Assert.assertEquals(expectedNumberOfDealerCards, goFish.getDealer().getHandSize()); + } + + @Test + public void playBooksTest() { + // Given + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + GoFish goFish = new GoFish(console); + Card testCard = new Card(Suit.HEARTS, Rank.THREE); + goFish.getDealer().addToHand(testCard); + goFish.getDealer().addToHand(testCard); + goFish.getDealer().addToHand(testCard); + goFish.getDealer().addToHand(testCard); + + // When + goFish.playBooks(); + String actual = outputStream.toString(); + + // Then + int expectedNumberOfDealerCards = 0; + Assert.assertTrue(actual.contains("Alright, I'm going to play these:")); + Assert.assertEquals(expectedNumberOfDealerCards, goFish.getDealer().getHandSize()); + } + + @Test + public void playBooksTest2() { + // Given + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + GoFish goFish = new GoFish(console); + Card testCard = new Card(Suit.HEARTS, Rank.THREE); + Card otherCard = new Card(Suit.HEARTS, Rank.ACE); + goFish.getDealer().addToHand(testCard); + goFish.getDealer().addToHand(testCard); + goFish.getDealer().addToHand(testCard); + goFish.getDealer().addToHand(testCard); + goFish.getDealer().addToHand(otherCard); + + // When + goFish.playBooks(); + String actual = outputStream.toString(); + + // Then + int expectedNumberOfDealerCards = 1; + Assert.assertTrue(actual.contains("Alright, I'm going to play these:")); + Assert.assertEquals(expectedNumberOfDealerCards, goFish.getDealer().getHandSize()); + } + + @Test + public void playBooksTest3() { + // Given + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + GoFish goFish = new GoFish(console); + Card testCard = new Card(Suit.HEARTS, Rank.THREE); + Card otherCard = new Card(Suit.HEARTS, Rank.ACE); + goFish.getDealer().addToHand(testCard); + goFish.getDealer().addToHand(testCard); + goFish.getDealer().addToHand(otherCard); + + // When + goFish.playBooks(); + String actual = outputStream.toString(); + + // Then + int expectedNumberOfDealerCards = 3; + Assert.assertFalse(actual.contains("Alright, I'm going to play these:")); + Assert.assertEquals(expectedNumberOfDealerCards, goFish.getDealer().getHandSize()); + } + + @Test + public void playTest() { + // Given + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + + // When + testGoFish.setIsOver(true); + testGoFish.play(); + String actualString = outputStream.toString(); + + // Then + String expectedString = "The object of this game is to get the most books (4 of a kind) down"; + Assert.assertFalse(actualString.contains("Alright, I'm going to play these:")); + Assert.assertTrue(actualString.contains(expectedString)); + } + + @Test + public void testUserTurn() { + // Given + String input = "king\nace"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + + // When + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.userTurn(); + + // Then + String actual = outputStream.toString(); + Assert.assertTrue(actual.contains("You can only ask for cards you have")); + } + + @Test + public void testUserTurn2() { + // Given + String input = "ace"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + + // When + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.userTurn(); + + // Then + String actual = outputStream.toString(); + Assert.assertTrue(actual.contains("Go Fish!")); + } + + @Test + public void testUserTurn3() { + // Given + String input = "ace\nking"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.KING)); + testGoFish.getDealer().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + + // When + testGoFish.userTurn(); + + // Then + int expectedCards = 0; + int actualCards = testGoFish.getDealer().getHandSize(); + String actual = outputStream.toString(); + Assert.assertTrue(actual.contains("You got me")); + Assert.assertEquals(expectedCards, actualCards); + } + + @Test + public void testUserTurnWithBook() { + // Given + String input = "ace\nyes\nace"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + testGoFish.getDealer().addToHand(new Card(Suit.HEARTS, Rank.KING)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + + // When + testGoFish.userTurn(); + + // Then + int expectedCards = 1; + int actualCards = testGoFish.getUser().getHandSize(); + Assert.assertEquals(expectedCards, actualCards); + } + + @Test + public void testBookTurn0() { + // Given + String input = "ace\nyes\nking"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + testGoFish.getDealer().addToHand(new Card(Suit.HEARTS, Rank.KING)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + + // When + testGoFish.bookTurn(); + + // Then + int expectedCards = 4; + int actualCards = testGoFish.getUser().getHandSize(); + Assert.assertEquals(expectedCards, actualCards); + } + + @Test + public void testBookTurn() { + // Given + String input = "no"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + + // When + testGoFish.bookTurn(); + + // Then + int expectedCards = 4; + int actualCards = testGoFish.getUser().getHandSize(); + Assert.assertEquals(expectedCards, actualCards); + } + + @Test + public void testBookTurn2() { + // Given + String input = "yes\nace"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + System.out.print(outputStream.toString()); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + + // When + testGoFish.bookTurn(); + + // Then + int expectedCards = 0; + int actualCards = testGoFish.getUser().getHandSize(); + Assert.assertEquals(expectedCards, actualCards); + } + + @Test + public void testBookTurn3() { + // Given + String input = "yes\nking\nace"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + + // When + testGoFish.bookTurn(); + + // Then + int expectedCards = 4; + int actualCards = testGoFish.getUser().getHandSize(); + String actual = outputStream.toString(); + Assert.assertEquals(expectedCards, actualCards); + Assert.assertTrue(actual.contains("That's not a book.")); + } + + @Test + public void testBookTurn4() { + // Given + String input = "yes\nace\nyes\nthree"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.THREE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.THREE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.THREE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.THREE)); + + + // When + testGoFish.bookTurn(); + + // Then + int expectedCards = 0; + int actualCards = testGoFish.getUser().getHandSize(); + Assert.assertEquals(expectedCards, actualCards); + } + + @Test + public void testGoFish() { + // Given + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + testGoFish.getDeck().drawMultipleCards(52); + + // When + testGoFish.goFish(testGoFish.getUser(), null); + + // Then + String actual = outputStream.toString(); + Assert.assertTrue(actual.contains("There are no more cards in the deck")); + } + + @Test + public void testGoFish2() { + // Given + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + Collections.sort(testGoFish.getDeck().getPlayDeck()); + + // When + testGoFish.goFish(testGoFish.getUser(), "ace"); + + // Then + String actual = outputStream.toString(); + System.out.print(outputStream.toString()); + Assert.assertTrue(actual.contains("Fish, Fish, you got your wish!")); + } + + @Test + public void testDisplayStatus() { + // Given + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.ACE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.THREE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.THREE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.THREE)); + testGoFish.getUser().addToHand(new Card(Suit.HEARTS, Rank.THREE)); + + // When + testGoFish.displayStatus(); + + //Then + String expected = "3━━━┓3━━━┓3━━━┓3━━━┓A━━━┓A━━━┓A━━━┓A━━━┓\n" + + "┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃\n" + + "┃ ♡ ┃┃ ♡ ┃┃ ♡ ┃┃ ♡ ┃┃ ♡ ┃┃ ♡ ┃┃ ♡ ┃┃ ♡ ┃\n" + + "┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃\n" + + "┗━━━3┗━━━3┗━━━3┗━━━3┗━━━A┗━━━A┗━━━A┗━━━A\n" + + "YOU: 0 DEALER: 0\n"; + String actual = outputStream.toString(); + Assert.assertEquals(expected, actual); + + } + + @Test + public void testEvaluate() { + // Given + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + + + // When + testGoFish.evaluate(); + + //Then + + Assert.assertFalse(testGoFish.isOver()); + + } + + @Test + public void testEvaluate2() { + // Given + String input = "no"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + testGoFish.getDealer().addToHand(testGoFish.getDeck().drawMultipleCards(52)); + testGoFish.playBooks(); + + + // When + testGoFish.evaluate(); + + //Then + String actual = outputStream.toString(); + String expected = "Alright, I'm going to play these:\n" + + "K━━━┓K━━━┓K━━━┓K━━━┓Q━━━┓Q━━━┓Q━━━┓Q━━━┓J━━━┓J━━━┓J━━━┓J━━━┓10━━┓10━━┓10━━┓10━━┓9━━━┓9━━━┓9━━━┓9━━━┓8━━━┓8━━━┓8━━━┓8━━━┓7━━━┓7━━━┓7━━━┓7━━━┓6━━━┓6━━━┓6━━━┓6━━━┓5━━━┓5━━━┓5━━━┓5━━━┓4━━━┓4━━━┓4━━━┓4━━━┓3━━━┓3━━━┓3━━━┓3━━━┓2━━━┓2━━━┓2━━━┓2━━━┓A━━━┓A━━━┓A━━━┓A━━━┓\n" + + "┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃\n" + + "┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃┃ ♧ ┃┃ ♢ ┃┃ ♡ ┃┃ ♤ ┃\n" + + "┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃┃ ┃\n" + + "┗━━━K┗━━━K┗━━━K┗━━━K┗━━━Q┗━━━Q┗━━━Q┗━━━Q┗━━━J┗━━━J┗━━━J┗━━━J┗━━10┗━━10┗━━10┗━━10┗━━━9┗━━━9┗━━━9┗━━━9┗━━━8┗━━━8┗━━━8┗━━━8┗━━━7┗━━━7┗━━━7┗━━━7┗━━━6┗━━━6┗━━━6┗━━━6┗━━━5┗━━━5┗━━━5┗━━━5┗━━━4┗━━━4┗━━━4┗━━━4┗━━━3┗━━━3┗━━━3┗━━━3┗━━━2┗━━━2┗━━━2┗━━━2┗━━━A┗━━━A┗━━━A┗━━━A\n" + + "\n" + + "Looks like I beat you this time. Come back anytime!\n"; + Assert.assertTrue(testGoFish.isOver()); + Assert.assertEquals(expected, actual); + + } + + @Test + public void testEvaluate3() { + // Given + String input = "yes\nace\nyes\ntwo\nyes\nthree\nyes\nfour\nyes\nfive\nyes\nsix\nyes\nseven\nyes\neight\nyes\nnine\nyes\n10\nyes\njs\nyes\nqueen\nyes\nkings"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + GoFish testGoFish = new GoFish(console); + testGoFish.getUser().addToHand(testGoFish.getDeck().drawMultipleCards(52)); + testGoFish.bookTurn(); + System.out.print(Card.printAllCards(testGoFish.getUser().getHand())); + System.out.print(outputStream.toString()); + + // When + testGoFish.evaluate(); + + //Then + String actual = outputStream.toString(); + String expected = "You won! Great game.\n"; + Assert.assertTrue(testGoFish.isOver()); + Assert.assertTrue(actual.contains(expected)); + + } +} diff --git a/src/test/java/io/zipcoder/casino/casino/GameTest/LoadedDiceTest.java b/src/test/java/io/zipcoder/casino/casino/GameTest/LoadedDiceTest.java new file mode 100644 index 000000000..54cbb7648 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/GameTest/LoadedDiceTest.java @@ -0,0 +1,22 @@ +package io.zipcoder.casino.casino.GameTest; + +import io.zipcoder.casino.casino.games.dicegames.diceutilities.LoadedDice; +import org.junit.Assert; +import org.junit.Test; + +public class LoadedDiceTest { + + @Test + public void rollTest() { + // Given a set of loaded dice exist and we expect a roll of 5 + LoadedDice dice = new LoadedDice(5); + int expected = 5; + + // When we roll the loaded die + int actual = dice.roll(); + + // Then we expect the given value and retrieved to be the same + Assert.assertEquals(expected, actual); + + } +} diff --git a/src/test/java/io/zipcoder/casino/casino/GameTest/MacaoTest.java b/src/test/java/io/zipcoder/casino/casino/GameTest/MacaoTest.java new file mode 100644 index 000000000..169d922a4 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/GameTest/MacaoTest.java @@ -0,0 +1,627 @@ +package io.zipcoder.casino.casino.GameTest; + +import io.zipcoder.casino.casino.games.dicegames.diceutilities.Dice; +import io.zipcoder.casino.casino.games.dicegames.diceutilities.LoadedDice; +import io.zipcoder.casino.casino.games.dicegames.Macao; +import org.junit.Assert; +import org.junit.Test; +import io.zipcoder.casino.casino.utilities.Console; + +import java.io.*; +import java.util.Scanner; + +public class MacaoTest { + + private Macao macao = new Macao(); + private ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + private Console console = new Console(System.in, new PrintStream(outputStream)); + + @Test + public void ConstructorTest() { + // Given macao data + boolean expectedIsOver = false; + boolean expectedGuestIsPlaying = true; + boolean expectedDealerIsPlaying = true; + + // When the data is retrieved from the game instance + boolean actualIsOver = macao.getIsOver(); + boolean actualGuestIsPlaying = macao.getGuestStillPlaying(); + boolean actualDealerIsPlaying = macao.getDealerStillPlaying(); + + // Then you expect the given data to match the retrieved data + Assert.assertEquals(expectedIsOver, actualIsOver); + Assert.assertEquals(expectedGuestIsPlaying ,actualGuestIsPlaying); + Assert.assertEquals(expectedDealerIsPlaying, actualDealerIsPlaying); + } + + @Test + public void getIsOverTest() { + // Given an expected boolean exists + boolean expected = true; + + // When the variable for 'is over' is set to the expected value + macao.setIsOver(expected); + + // When we retrieve the variable for 'is over' from the game + boolean actual = macao.getIsOver(); + + // We expect the given data to match the retrieved data + Assert.assertEquals(expected, actual); + + } + + @Test + public void setIsOverTest() { + // Given an initial variable for 'is Over' (which is false upon construction) + boolean initial = macao.getIsOver(); + + // When we set the 'is Over' variable to true + macao.setIsOver(true); + + // When we retrieve the 'is Over' variable from the game + boolean changed = macao.getIsOver(); + + // Then we expect the initial to be false and the changed variable to be true + Assert.assertFalse(initial); + Assert.assertTrue(changed); + } + + @Test + public void getGuestStillPlayingTest() { + // Given an expected boolean exists + boolean expected = true; + + // When the variable for 'guest still playing' is set to the expected value + macao.setGuestStillPlaying(expected); + + // When we retrieve the variable for 'guest still playing' from the game + boolean actual = macao.getGuestStillPlaying(); + + // We expect the given data to match the retrieved data + Assert.assertEquals(expected, actual); + + } + + @Test + public void setGuestStillPlayingTest() { + // Given an initial variable for 'guest still playing' (which is true upon construction) + boolean initial = macao.getGuestStillPlaying(); + + // When we set the 'guest still playing' variable to true + macao.setGuestStillPlaying(false); + + // When we retrieve the 'guest still playing' variable from the game + boolean changed = macao.getGuestStillPlaying(); + + // Then we expect the initial to be true and the changed variable to be false + Assert.assertTrue(initial); + Assert.assertFalse(changed); + } + + @Test + public void getDealerStillPlayingTest() { + // Given an expected boolean exists + boolean expected = true; + + // When the variable for 'dealer still playing' is set to the expected value + // + macao.setDealerStillPlaying(expected); + + // When we retrieve the variable for 'dealer still playing' from the game + boolean actual = macao.getDealerStillPlaying(); + + // We expect the given data to match the retrieved data + Assert.assertEquals(expected, actual); + + } + + @Test + public void setDealerStillPlayingTest() { + // Given an initial variable for 'dealer still playing' (which is true upon construction) + boolean initial = macao.getDealerStillPlaying(); + + // When we set the 'dealer still playing' variable to true + macao.setDealerStillPlaying(false); + + // When we retrieve the 'dealer still playing' variable from the game + boolean changed = macao.getDealerStillPlaying(); + + // Then we expect the initial to be true and the changed variable to be false + Assert.assertTrue(initial); + Assert.assertFalse(changed); + } + + @Test + public void playGameTest1() { + // Given the macao dice are set to our loaded dice + Dice dice = new LoadedDice(5); + macao.setDice(dice); + + // Given the user says "yes" they'd like to play and "yes" they'd like to roll again + ByteArrayInputStream inputStream = new ByteArrayInputStream("yes\nyes".getBytes()); + Console ioconsole = new Console(new Scanner(inputStream), new PrintStream(outputStream)); + macao.setConsole(ioconsole); + + // Given the expected string + String expected = + "Oh no! Looks like you went over! You lose."; + + // When we call the play game method and store the output in a variable + macao.play(); + String actual = outputStream.toString().trim(); + + // Then we expect the given and retrieved strings to match + Assert.assertTrue(actual.contains(expected)); + } + + @Test + public void playGameTest2() { + // Given the macao dice are set to our loaded dice + Dice dice = new LoadedDice(5); + macao.setDice(dice); + + // Given the user says "yes" they'd like to play and "no" they wouldn't like to roll again + ByteArrayInputStream inputStream = new ByteArrayInputStream("yes\nno".getBytes()); + Console ioconsole = new Console(new Scanner(inputStream), new PrintStream(outputStream)); + macao.setConsole(ioconsole); + + // Given the expected string + String expected = + "Lucky you! The dealer went over. YOU WIN!"; + + // When we call the play game method and store the output in a variable + macao.play(); + System.out.println(outputStream.toString()); + String actual = outputStream.toString().trim(); + + // Then we expect the given and retrieved strings to match + Assert.assertTrue(actual.contains(expected)); + } + + @Test + public void printGameInstructionsTest() { + // Given the expected string + String expected = "Rules:\nThe object of this game is to roll the die enough times to reach a total of 9 without going over.\nGood luck!"; + + // When the console is changed to the test console + macao.setConsole(console); + + // When the print game instructions method is called (trim has to be called also to fix new line error) + macao.printGameInstructions(); + String actual = outputStream.toString(); + actual = actual.trim(); + + // Then we expect the given data to match the retrieved data + Assert.assertEquals(expected, actual); + } + + @Test + public void beginGameTest1() { + // Given user input = 'y' and the console is set to our console + ByteArrayInputStream inputByteArray = new ByteArrayInputStream("y".getBytes()); + Console ioconsole = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + macao.setConsole(ioconsole); + + // When begin game is called + boolean retrieved = macao.beginGame(); + + // Then the retrieved boolean should be true (i.e. the game should begin) + Assert.assertTrue(retrieved); + } + + @Test + public void beginGameTest2() { + // Given user input = 'x' and the console is set to our console + ByteArrayInputStream inputByteArray = new ByteArrayInputStream("x\nyes".getBytes()); + Console ioconsole = new Console(new Scanner(inputByteArray), new PrintStream(outputStream)); + macao.setConsole(ioconsole); + + // Given the expected string output + String expected = "Are you ready to begin?\n" + + "Hm, I expected something different. Are you ready to begin?"; + + // When begin game is called & the output stored in a variable + boolean retrieved = macao.beginGame(); + String actual = outputStream.toString().trim(); + + // Then the retrieved boolean should be true (since the second input is 'yes') & the given string should match the actual string + Assert.assertTrue(retrieved); + Assert.assertEquals(expected, actual); + } + + @Test + public void rollDieTest() { + // Given players initial dice roll + macao.getUser().setRoll(4); + + // Given we set the macao dice to our loaded dice; given an expected roll of 5 + Dice dice = new LoadedDice(5); + macao.setDice(dice); + int expected = 5; + + // When the roll die method is called + macao.rollDie(macao.getUser()); + + // When we retrieve the current roll from the player + int actual = macao.getUser().getRoll(); + + // Then we expect the new roll to equal the expected + Assert.assertEquals(expected, actual); + } + + @Test + public void showInitialRollsTest() { + // Given we set the guest's roll to 3 and the dealer's roll to 4 + macao.getUser().setRoll(3); + macao.getDealer().setRoll(4); + + // Given the expected string + String expected = "YOUR ROLL DEALER'S ROLL\n" + + "┏━━━━━━━━┓ ┏━━━━━━━━┓ \n" + + "┃ ⬤ ┃ ┃ ⬤ ⬤ ┃ \n" + + "┃ ⬤ ┃ ┃ ┃ \n" + + "┃ ⬤ ┃ ┃ ⬤ ⬤ ┃ \n" + + "┗━━━━━━━━┛ ┗━━━━━━━━┛"; + + // When we set the console to the test console + macao.setConsole(console); + + // When we print out the initial rolls and store the string output in a variable + macao.showInitialRolls(); + String actual = outputStream.toString(); + actual = actual.trim(); + + // Then we expect the given and the retrieved data to match + Assert.assertEquals(expected, actual); + } + + @Test + public void showGuestRollTest() { + // Given we set the guest's current roll to 4 and cumulative roll to 5 + macao.getUser().setRoll(4); + macao.getUser().setCumulativeRoll(10); + + // Given the expected string + String expected = "YOUR NEW ROLL\n" + + "┏━━━━━━━━┓ \n" + + "┃ ⬤ ⬤ ┃ \n" + + "┃ ┃ \n" + + "┃ ⬤ ⬤ ┃ \n" + + "┗━━━━━━━━┛ \n" + + "YOUR TOTAL IS NOW... 10\n" + + "HERE'S WHAT YOU ROLLED SO FAR\n" + + "┏━━━━━━━━┓\n" + + "┃ ⬤ ⬤ ┃\n" + + "┃ ┃\n" + + "┃ ⬤ ⬤ ┃\n" + + "┗━━━━━━━━┛"; + + // When we set the console to the test console + macao.setConsole(console); + + // When we print out the initial rolls and store the string output in a variable + macao.showGuestRoll(); + String actual = outputStream.toString(); + actual = actual.trim(); + + // Then we expect the given and the retrieved data to match + Assert.assertEquals(expected, actual); + } + + @Test + public void showDealerRollTest() { + // Given we set the dealer's current roll to 3 and cumulative roll to 8 + macao.getDealer().setRoll(3); + macao.getDealer().setCumulativeRoll(8); + + // Given the expected string + String expected = "DEALERS'S NEW ROLL\n" + + "┏━━━━━━━━┓\n" + + "┃ ⬤ ┃\n" + + "┃ ⬤ ┃\n" + + "┃ ⬤ ┃\n" + + "┗━━━━━━━━┛\n" + + "THE DEALERS'S TOTAL IS NOW... 8\n" + + "HERE'S WHAT THE DEALER ROLLED SO FAR\n" + + "┏━━━━━━━━┓\n" + + "┃ ⬤ ┃\n" + + "┃ ⬤ ┃\n" + + "┃ ⬤ ┃\n" + + "┗━━━━━━━━┛"; + + // When we set the console to the test console + macao.setConsole(console); + + // When we print out the initial rolls and store the string output in a variable + macao.showDealerRoll(); + String actual = outputStream.toString(); + actual = actual.trim(); + + // Then we expect the given and the retrieved data to match + Assert.assertEquals(expected, actual); + } + + @Test + public void initialGameSetupTest() { + // Given a set of loaded die are set to our macao die + Dice dice = new LoadedDice(5); + macao.setDice(dice); + + // Given the console is set to our test console & we expect the initial rolls to print + macao.setConsole(console); + String expected = "YOUR ROLL DEALER'S ROLL\n" + + "┏━━━━━━━━┓ ┏━━━━━━━━┓ \n" + + "┃ ⬤ ⬤ ┃ ┃ ⬤ ⬤ ┃ \n" + + "┃ ⬤ ┃ ┃ ⬤ ┃ \n" + + "┃ ⬤ ⬤ ┃ ┃ ⬤ ⬤ ┃ \n" + + "┗━━━━━━━━┛ ┗━━━━━━━━┛"; + + // When the initial game setup method is called & we store the string output in a variable + macao.initialGameSetup(); + String actual = outputStream.toString().trim(); + + // Then we expect the given and retrieved strings to match + Assert.assertEquals(expected, actual); + } + + @Test + public void isGuestStillPlayingTest1() { + // Given the guests cumulative roll is set to 9 + macao.getUser().setCumulativeRoll(9); + + // When the is guest still playing method is called and the outcome stored in a variable + boolean retrieved = macao.isGuestStillPlaying(); + + // Then we expect it to return false because the guest would no longer be playing with a total of 9 + Assert.assertFalse(retrieved); + } + + @Test + public void isGuestStillPlayingTest2() { + // Given the guest says they do want to roll again & the console is set to our test console + ByteArrayInputStream inputBytes = new ByteArrayInputStream("yes".getBytes()); + Console ioconsole = new Console(new Scanner(inputBytes), new PrintStream(outputStream)); + macao.setConsole(ioconsole); + + // Given the expected string + String expected = "Would you like to roll again?\nGreat, here's your die."; + + // When we call the is guest still playing method + macao.isGuestStillPlaying(); + String actual = outputStream.toString().trim(); + + // Then we expect the strings to match + Assert.assertEquals(expected, actual); + } + + @Test + public void isGuestStillPlayingTest3() { + // Given the guest says they don't want to roll again & the console is set to our test console + ByteArrayInputStream inputBytes = new ByteArrayInputStream("no".getBytes()); + Console ioconsole = new Console(new Scanner(inputBytes), new PrintStream(outputStream)); + macao.setConsole(ioconsole); + + // Given the expected string + String expected = "Would you like to roll again?\nBold tactic."; + + // When we call the is guest still playing method + macao.isGuestStillPlaying(); + String actual = outputStream.toString().trim(); + + // Then we expect the strings to match + Assert.assertEquals(expected, actual); + } + + @Test + public void isGuestStillPlayingTest4() { + // Given the guest enters something other than yes or no & the console is set to our test console + ByteArrayInputStream inputBytes = new ByteArrayInputStream("huh\nyes".getBytes()); + Console ioconsole = new Console(new Scanner(inputBytes), new PrintStream(outputStream)); + macao.setConsole(ioconsole); + + // Given the expected string (what we expect for "huh" followed by what we expect for "yes" + String expected = "Would you like to roll again?\n" + + "I didn't catch that.\n" + + "Would you like to roll again?\n" + + "Great, here's your die."; + + // When we call the is guest still playing method + macao.isGuestStillPlaying(); + String actual = outputStream.toString().trim(); + + // Then we expect the strings to match + Assert.assertEquals(expected, actual); + } + + @Test + public void youWentOverTest() { + // Given the expected string + String expected = "Oh no! Looks like you went over! You lose."; + + // When we set the console to the test console + macao.setConsole(console); + + // When we call the you went over method & store the string output in a variable + macao.youWentOver(); + String actual = outputStream.toString().trim(); + + // Then we expect the given string to match the retrieved string. + Assert.assertEquals(expected, actual); + } + + @Test + public void didGuestGoOverTest1() { + // Given the guest has a cumulative roll of 10 + int cumuRoll = 10; + macao.getUser().setCumulativeRoll(cumuRoll); + + // When we call the 'did guest go over method' + Boolean guestWentOver = macao.didGuestGoOver(); + + // Then we expect guestWentOver to be true since 10 is over 9 + Assert.assertTrue(guestWentOver); + } + + @Test + public void didGuestGoOverTest2() { + // Given the guest has a cumulative roll of 7 + int cumuRoll = 7; + macao.getUser().setCumulativeRoll(cumuRoll); + + // When we call the 'did guest go over method' + Boolean guestWentOver = macao.didGuestGoOver(); + + // Then we expect guestWentOver to be false since 7 under 9 + Assert.assertFalse(guestWentOver); + } + + @Test + public void dealerStillPlayingTest1() { + // Given the dealers cumulative roll is 7 and the guest's cumulative roll is 6 + macao.getDealer().setCumulativeRoll(7); + macao.getUser().setCumulativeRoll(6); + + // When we call the 'dealer still playing function' + Boolean dealerStillPlaying = macao.isDealerStillPlaying(); + + // Then we expect it to return false because the dealers roll is both over 7 and over the guests cumulative roll + Assert.assertFalse(dealerStillPlaying); + } + + @Test + public void dealerStillPlayingTest2() { + // Given the dealer's cumulative roll is 4 and the guest's cumulative roll is 8 + macao.getDealer().setCumulativeRoll(4); + macao.getUser().setCumulativeRoll(8); + + // When we call the 'dealer still playing function' + Boolean dealerStillPlaying = macao.isDealerStillPlaying(); + + // Then we expect it to return true because the dealers roll is both less than 9 and less than the guests cumulative roll + Assert.assertTrue(dealerStillPlaying); + } + + @Test + public void dealerStillPlayingTest3() { + // Given the dealer's cumulative roll is 4 and the guest's cumulative roll is 8 + macao.getDealer().setCumulativeRoll(9); + macao.getUser().setCumulativeRoll(8); + + // When we call the 'dealer still playing function' + Boolean dealerStillPlaying = macao.isDealerStillPlaying(); + + // Then we expect it to return false because the dealers roll is 9 + Assert.assertFalse(dealerStillPlaying); + } + + @Test + public void evaluateTest1() { + // Given the dealers cumulative roll is 10, the console is our test console, and we expect 'the dealer went over' to print + macao.getDealer().setCumulativeRoll(10); + macao.setConsole(console); + String expected = "Lucky you! The dealer went over. YOU WIN!"; + + // When we call the evaluate function & we store the output in a string variable + macao.evaluate(); + String actual = outputStream.toString().trim(); + + // When we retrieve the 'is Over' variable + boolean retrieved = macao.getIsOver(); + + // Then we expect 'is Over' to be true and the given/retrieved strings to match + Assert.assertTrue(retrieved); + Assert.assertEquals(expected, actual); + } + + @Test + public void evaluateTest2() { + // Given neither the guest nor dealer are still playing + macao.setGuestStillPlaying(false); + macao.setDealerStillPlaying(false); + + // Given the dealers cumulative roll is 7 and the guests cumulative roll is 8 + macao.getDealer().setCumulativeRoll(7); + macao.getUser().setCumulativeRoll(8); + + // Given the game console is set to our test console + macao.setConsole(console); + + // Given the expected string output + String expected = "Your total is 8 and the dealer's total is 7. You're our winner!"; + + // When we call the evaluate method + macao.evaluate(); + + // When we retrieve the 'is Over' variable + boolean gameOver = macao.getIsOver(); + + // When we retrieve the string output (& trim it) + String actual = outputStream.toString().trim(); + + // Then we expect the 'is Over' variable to be true and the given string to match the retrieved string + Assert.assertTrue(gameOver); + Assert.assertEquals(expected, actual); + } + + @Test + public void evaluateTest3() { + // Given neither the guest nor dealer are still playing + macao.setGuestStillPlaying(false); + macao.setDealerStillPlaying(false); + + // Given the dealers cumulative roll is 9 and the guests cumulative roll is 8 + macao.getDealer().setCumulativeRoll(9); + macao.getUser().setCumulativeRoll(8); + + // Given the game console is set to our test console + macao.setConsole(console); + + // Given the expected string output + String expected = "Your total is 8 and the dealer's total is 9. Better luck next time."; + + // When we call the evaluate method + macao.evaluate(); + + // When we retrieve the 'is Over' variable + boolean gameOver = macao.getIsOver(); + + // When we retrieve the string output (& trim it) + String actual = outputStream.toString().trim(); + + // Then we expect the 'is Over' variable to be true and the given string to match the retrieved string + Assert.assertTrue(gameOver); + Assert.assertEquals(expected, actual); + } + + @Test + public void evaluateTest4() { + // Given neither the guest nor dealer are still playing + macao.setGuestStillPlaying(false); + macao.setDealerStillPlaying(false); + + // Given the dealers cumulative roll is 9 and the guests cumulative roll is 9 + macao.getDealer().setCumulativeRoll(9); + macao.getUser().setCumulativeRoll(9); + + // Given the game console is set to our test console + macao.setConsole(console); + + // Given the expected string output + String expected = "You both rolled 9. It's a tie!"; + + // When we call the evaluate method + macao.evaluate(); + + // When we retrieve the 'is Over' variable + boolean gameOver = macao.getIsOver(); + + // When we retrieve the string output (& trim it) + String actual = outputStream.toString().trim(); + + // Then we expect the 'is Over' variable to be true and the given string to match the retrieved string + Assert.assertTrue(gameOver); + Assert.assertEquals(expected, actual); + } + + +} diff --git a/src/test/java/io/zipcoder/casino/casino/GoFishPlayerTest.java b/src/test/java/io/zipcoder/casino/casino/GoFishPlayerTest.java new file mode 100644 index 000000000..efe716226 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/GoFishPlayerTest.java @@ -0,0 +1,353 @@ +package io.zipcoder.casino.casino; + +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Card; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Deck; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Rank; +import io.zipcoder.casino.casino.games.cardgames.cardutilities.Suit; +import io.zipcoder.casino.casino.games.cardgames.GoFishPlayer; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class GoFishPlayerTest { + + @Test + public void testAddToHand() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Deck testDeck = new Deck(); + Card expected = testDeck.drawCard(); + + // When + testPlayer.addToHand(expected); + Card actual = testPlayer.getHand().get(0); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testAddMultiple() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Deck testDeck = new Deck(); + List expected = testDeck.drawMultipleCards(4); + List testSecond = testDeck.drawMultipleCards(4); + + // When + testPlayer.addToHand(expected); + testPlayer.addToHand(testSecond); + List actual = testPlayer.getHand(); + + // Then + expected.addAll(testSecond); + Collections.sort(expected); + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetHand() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Deck testDeck = new Deck(); + List expected = testDeck.drawMultipleCards(4); + + // When + testPlayer.setHand(expected); + List actual = testPlayer.getHand(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetHand2() { + // Given + List expected = new ArrayList<>(); + GoFishPlayer testPlayer = new GoFishPlayer(); + + // When + testPlayer.setHand(null); + List actual = testPlayer.getHand(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetIncreaseBookCount() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + + // When + testPlayer.increaseBookCount(); + int actual = testPlayer.getBookCount(); + + // Then + int expected = 1; + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetIncreaseBookCount2() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + + // When + testPlayer.increaseBookCount(); + testPlayer.increaseBookCount(); + testPlayer.increaseBookCount(); + testPlayer.increaseBookCount(); + int actual = testPlayer.getBookCount(); + + // Then + int expected = 4; + Assert.assertEquals(expected, actual); + } + + @Test + public void testHasCardTrue() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Card expected = new Card(Suit.HEARTS, Rank.THREE); + + // When + testPlayer.addToHand(expected); + boolean actual = testPlayer.hasCard(expected.getRank().toString().toUpperCase()); + + // Then + Assert.assertTrue(actual); + } + + @Test + public void testHasCardFalse() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Card cardInHand = new Card(Suit.HEARTS, Rank.ACE); + Card cardNotInHand = new Card(Suit.DIAMONDS, Rank.THREE); + + // When + testPlayer.addToHand(cardInHand); + boolean actual = testPlayer.hasCard(cardNotInHand.getRank().toString()); + + // Then + Assert.assertFalse(actual); + } + + @Test + public void testGetCards() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Card cardInHand = new Card(Suit.HEARTS, Rank.ACE); + List expected = new ArrayList<>(); + expected.add(cardInHand); + expected.add(cardInHand); + + // When + testPlayer.addToHand(cardInHand); + testPlayer.addToHand(cardInHand); + List actual = testPlayer.getCards(cardInHand.getRank().toString().toUpperCase()); + + // Then + Assert.assertEquals(expected, actual); + Assert.assertFalse(testPlayer.hasCard(cardInHand.getRank().toString().toUpperCase())); + } + + @Test + public void testGetCards2() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + new Card(Suit.HEARTS, Rank.ACE); + Card cardInHand = new Card(Suit.HEARTS, Rank.ACE); + Card otherCard = new Card(Suit.HEARTS, Rank.TWO); + List expected = new ArrayList<>(); + expected.add(cardInHand); + List expectedHand = new ArrayList<>(); + expectedHand.add(otherCard); + + // When + testPlayer.addToHand(cardInHand); + testPlayer.addToHand(otherCard); + List actual = testPlayer.getCards(cardInHand.getRank().toString()); + List hand = testPlayer.getHand(); + + // Then + Assert.assertEquals(expected, actual); + Assert.assertEquals(expectedHand, hand); + Assert.assertFalse(testPlayer.hasCard(cardInHand.getRank().toString())); + Assert.assertTrue(testPlayer.hasCard(otherCard.getRank().toString())); + } + + @Test + public void testGetRandomCard() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Deck testDeck = new Deck(); + Card testCard = testDeck.drawCard(); + testPlayer.addToHand(testCard); + + // When + Card actual = testPlayer.getRandomCard(); + + // Then + Assert.assertEquals(testCard, actual); + } + + @Test + public void testGetRandomCard2() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Deck testDeck = new Deck(); + Card testCard = testDeck.drawCard(); + Card otherCard = testDeck.drawCard(); + testPlayer.addToHand(testCard); + testPlayer.addToHand(otherCard); + + // When + Card actual = testPlayer.getRandomCard(); + + // Then + Assert.assertTrue(actual.equalRank(testCard) || actual.equalRank(otherCard)); + } + + @Test + public void testHasBooks() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Card cardInHand = new Card(Suit.HEARTS, Rank.ACE); + Card otherCard = new Card(Suit.HEARTS, Rank.TWO); + Card thirdCard = new Card(Suit.HEARTS, Rank.THREE); + Card fourthCard = new Card(Suit.HEARTS, Rank.FOUR); + testPlayer.addToHand(cardInHand); + testPlayer.addToHand(otherCard); + testPlayer.addToHand(thirdCard); + testPlayer.addToHand(fourthCard); + + // When + boolean actual = testPlayer.hasBooks(); + + // Then + Assert.assertFalse(actual); + } + + @Test + public void testHasBooks2() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + testPlayer.addToHand(new Card(Suit.HEARTS, Rank.ACE)); + + // When + boolean actual = testPlayer.hasBooks(); + + // Then + Assert.assertFalse(actual); + } + + @Test + public void testHasBooks3() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Deck testDeck = new Deck(); + testPlayer.addToHand(testDeck.drawMultipleCards(52)); + Collections.sort(testPlayer.getHand()); + // When + boolean actual = testPlayer.hasBooks(); + + // Then + Assert.assertTrue(actual); + } + + @Test + public void testHasBooks4() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Card cardInHand = new Card(Suit.HEARTS, Rank.ACE); + Card otherCard = new Card(Suit.DIAMONDS, Rank.ACE); + Card thirdCard = new Card(Suit.SPADES, Rank.ACE); + Card fourthCard = new Card(Suit.CLUBS, Rank.ACE); + testPlayer.addToHand(otherCard); + testPlayer.addToHand(cardInHand); + testPlayer.addToHand(thirdCard); + testPlayer.addToHand(fourthCard); + + // When + boolean actual = testPlayer.hasBooks(); + + // Then + Assert.assertTrue(actual); + } + + @Test + public void testGetBooks() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Card testCard = new Card(Suit.CLUBS, Rank.QUEEN); + List expected = new ArrayList<>(); + expected.add(testCard); + expected.add(testCard); + expected.add(testCard); + expected.add(testCard); + + testPlayer.addToHand(expected); + + // When + List actual = testPlayer.getBooks(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetBooks2() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Deck testDeck = new Deck(); + List expected = new ArrayList<>(); + expected.addAll(testDeck.drawMultipleCards(52)); + testPlayer.addToHand(expected); + Collections.sort(expected); + + // When + List actual = testPlayer.getBooks(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetHandSize() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + Card testCard = new Card(Suit.DIAMONDS, Rank.FIVE); + List testCards = new ArrayList<>(); + testCards.add(testCard); + testCards.add(testCard); + testCards.add(testCard); + testCards.add(testCard); + + testPlayer.addToHand(testCards); + + // When + int actual = testPlayer.getHandSize(); + + // Then + int expected = 4; + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetHandSize2() { + // Given + GoFishPlayer testPlayer = new GoFishPlayer(); + + // When + int actual = testPlayer.getHandSize(); + + // Then + int expected = 0; + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/casino/casino/GreeterTest.java b/src/test/java/io/zipcoder/casino/casino/GreeterTest.java new file mode 100644 index 000000000..23308cb9e --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/GreeterTest.java @@ -0,0 +1,379 @@ +package io.zipcoder.casino.casino; + +import io.zipcoder.casino.casino.games.cardgames.BlackJack; +import io.zipcoder.casino.casino.games.cardgames.GoFish; +import io.zipcoder.casino.casino.games.Game; +import io.zipcoder.casino.casino.games.dicegames.Craps; +import io.zipcoder.casino.casino.games.dicegames.Macao; +import io.zipcoder.casino.casino.utilities.Console; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + +public class GreeterTest { + @Test + public void testGetUserName() { + // Given + String expectedInput = "testName"; + byte[] inputBytes = expectedInput.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + String actualInput = greeter.getUserName(); + + // Then + Assert.assertEquals(expectedInput, actualInput); + } + + @Test + public void testGetUserName2() { + // Given + String expectedInput = "9990199User"; + byte[] inputBytes = expectedInput.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + String actualInput = greeter.getUserName(); + + // Then + Assert.assertEquals(expectedInput, actualInput); + } + + @Test + public void testGetUserName3() { + // Given + String expectedInput = "Jane Doe"; + byte[] inputBytes = "".getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + String actualInput = greeter.getUserName(); + + // Then + Assert.assertEquals(expectedInput, actualInput); + } + + + @Test + public void testGetIfGambling() { + // Given + String input = "12"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + boolean isGambling = greeter.getIfGambling("Mary"); + + // Then + Assert.assertFalse(isGambling); + } + + @Test + public void testGetIfGambling2() { + // Given + String input = "21\nyes"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + boolean isGambling = greeter.getIfGambling("Mary"); + + // Then + Assert.assertTrue(isGambling); + } + + @Test + public void testGetIfGambling3() { + // Given + String input = "21\n no"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + boolean isGambling = greeter.getIfGambling("Mary"); + + // Then + Assert.assertFalse(isGambling); + } + + @Test + public void testGetIfGambling4() { + // Given + String input = "21\n asdfasdf"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + boolean isGambling = greeter.getIfGambling("Mary"); + + // Then + Assert.assertTrue(isGambling); + } + + @Test + public void testGetNextClean() { + // Given + String input = "gofish"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextCleanGame(); + + // Then + Assert.assertTrue(game instanceof GoFish); + } + + @Test + public void testGetNextClean2() { + // Given + String input = "macao"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextCleanGame(); + + // Then + Assert.assertTrue(game instanceof Macao); + } + + @Test + public void testGetNextClean3() { + // Given + String input = "blackjack"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextCleanGame(); + + // Then + Assert.assertTrue(game instanceof GoFish); + } + + @Test + public void testGetNextGame() { + // Given + String input = "blackjack"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextGame(); + + // Then + Assert.assertTrue(game instanceof BlackJack); + } + + @Test + public void testGetNextGame2() { + // Given + String input = "gofish"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextGame(); + + // Then + Assert.assertTrue(game instanceof GoFish); + } + + @Test + public void testGetNextGame3() { + // Given + String input = "djkldfsjklfadskl;"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextGame(); + + // Then + Assert.assertTrue(game instanceof GoFish); + } + + @Test + public void testGetNextGame4() { + // Given + String input = "craps"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextGame(); + + // Then + Assert.assertTrue(game instanceof Craps); + } + + @Test + public void testGetNextGame5() { + // Given + String input = "macao"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + Game game = greeter.getNextGame(); + + // Then + Assert.assertTrue(game instanceof Macao); + } + + @Test + public void getIfLeavingTest() { + // Given + String input = "no"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + boolean isLeaving = greeter.getIfLeaving(); + + // Then + Assert.assertTrue(isLeaving); + } + + @Test + public void getIfLeavingTest2() { + // Given + String input = "asdfasdf"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + boolean isLeaving = greeter.getIfLeaving(); + + // Then + Assert.assertFalse(isLeaving); + } + + @Test + public void getIfLeavingTest3() { + // Given + String input = "yes"; + byte[] inputBytes = input.getBytes(); + ByteArrayInputStream inputByteArray = new ByteArrayInputStream(inputBytes); + Console console = new Console(new Scanner(inputByteArray), System.out); + Greeter greeter = new Greeter(console); + + // When + boolean isLeaving = greeter.getIfLeaving(); + + // Then + Assert.assertFalse(isLeaving); + } + + @Test + public void balanceTooLowTest() { + + // Given + String expected = String.format("Sorry, your balance is too low to keep playing.\n"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + + // When + greeter.balanceTooLow(); + String actual = outputStream.toString(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void goodByeTest() { + // Given + String expected = String.format("Thank you so much for coming! Please come again!\n"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Console console = new Console(System.in, new PrintStream(outputStream)); + Greeter greeter = new Greeter(console); + + // When + greeter.goodBye(); + String actual = outputStream.toString(); + + // Then + Assert.assertTrue(actual.contains(expected)); + } + + @Test + public void getBlackJackNameTest() { + // Given + String expected = + "██████╗ ██╗ █████╗ ██████╗██╗ ██╗ ██╗ █████╗ ██████╗██╗ ██╗\n" + + "██╔══██╗██║ ██╔══██╗██╔════╝██║ ██╔╝ ██║██╔══██╗██╔════╝██║ ██╔╝\n" + + "██████╔╝██║ ███████║██║ █████╔╝ ██║███████║██║ █████╔╝ \n" + + "██╔══██╗██║ ██╔══██║██║ ██╔═██╗ ██ ██║██╔══██║██║ ██╔═██╗ \n" + + "██████╔╝███████╗██║ ██║╚██████╗██║ ██╗╚█████╔╝██║ ██║╚██████╗██║ ██╗\n" + + "╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚════╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝\n" + + " "; + Greeter greeter = new Greeter(); + + // When + String actual = greeter.getBlackJackName(); + + // Then + Assert.assertTrue(actual.contains(expected)); + } + + @Test + public void getCrapsNameTest() { + // Given + String expected = + " ██████╗██████╗ █████╗ ██████╗ ███████╗\n" + + "██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝\n" + + "██║ ██████╔╝███████║██████╔╝███████╗\n" + + "██║ ██╔══██╗██╔══██║██╔═══╝ ╚════██║\n" + + "╚██████╗██║ ██║██║ ██║██║ ███████║\n" + + " ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══════╝\n" + + " "; + Greeter greeter = new Greeter(); + + // When + String actual = greeter.getCrapsName(); + + // Then + Assert.assertTrue(actual.contains(expected)); + } +} diff --git a/src/test/java/io/zipcoder/casino/casino/MacaoPlayerTest.java b/src/test/java/io/zipcoder/casino/casino/MacaoPlayerTest.java new file mode 100644 index 000000000..e9ec07497 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/casino/MacaoPlayerTest.java @@ -0,0 +1,108 @@ +package io.zipcoder.casino.casino; + +import io.zipcoder.casino.casino.games.dicegames.MacaoPlayer; +import org.junit.Assert; +import org.junit.Test; + +public class MacaoPlayerTest { + + @Test + public void constructorTest1() { + // Given the expected roll and cumulative roll are both zero + int expectedRoll = 0; + int expectedCumuRoll = 0; + + // When we construct a new macaoPlayer with the default constuctor + MacaoPlayer macaoPlayer = new MacaoPlayer(); + + // When we retrieve the roll & cumulative roll from the macaoPlayer instance + int actualRoll = macaoPlayer.getRoll(); + int actualCumuRoll = macaoPlayer.getCumulativeRoll(); + + // Then we expect the given data to match the retrieved data + Assert.assertEquals(expectedRoll, actualRoll); + Assert.assertEquals(expectedCumuRoll, actualCumuRoll); + } + + @Test + public void constructorTest2() { + // Given a profile exists with name Ashley and gambling status false + Profile expectedProfile = new Profile("Ashley", false); + + // Given the expected roll and cumulative roll are both zero + int expectedRoll = 0; + int expectedCumuRoll = 0; + + // When we construct a new macaoPlayer with the given profile + MacaoPlayer macaoPlayer = new MacaoPlayer(expectedProfile); + + // When we retrieve the profile, roll, and cumulative roll from the player instance + Profile actualProfile = macaoPlayer.getProfile(); + int actualRoll = macaoPlayer.getRoll(); + int actualCumuRoll = macaoPlayer.getCumulativeRoll(); + + // Then we expect the given data to match the retrieved data + Assert.assertEquals(expectedProfile, actualProfile); + Assert.assertEquals(expectedRoll, actualRoll); + Assert.assertEquals(expectedCumuRoll, actualCumuRoll); + } + + @Test + public void getProfileTest() { + // Given a player exists with a given profile + Profile expected = new Profile ("Abby", true); + MacaoPlayer player = new MacaoPlayer(expected); + + // When we call the get profile method & store it in a variable + Profile actual = player.getProfile(); + + // Then we expected the given and retrieved profiles to match + Assert.assertEquals(expected, actual); + } + + @Test + public void getRollTest() { + // Given a player exists with a current roll of 5 + MacaoPlayer player = new MacaoPlayer(); + int expected = 5; + player.setRoll(expected); + + // When we call the get roll method + int actual = player.getRoll(); + + // Then we expect the given data to match the retrieved data + Assert.assertEquals(expected, actual); + } + + @Test + public void getCumulativeRollTest1() { + // Given a player exists with a cumulative roll of 8 + MacaoPlayer player = new MacaoPlayer(); + int expected = 8; + player.setCumulativeRoll(expected); + + // When we call the get cumulative roll method + int actual = player.getCumulativeRoll(); + + // Then we expect the given data to match the retrieved data + Assert.assertEquals(expected, actual); + + } + + @Test + public void getCumulativeRollTest2() { + // Given a player exists with a cumulative roll of 8 + MacaoPlayer player = new MacaoPlayer(); + int roll1 = 6; + int roll2 = 4; + int expected = roll1 + roll2; + player.setRoll(roll1); + player.setRoll(roll2); + + // When we call the get cumulative roll method + int actual = player.getCumulativeRoll(); + + // Then we expect the given data to match the retrieved data + Assert.assertEquals(expected, actual); + } +}