def test_betting(monkeypatch): """ Testing different things we can do with betting """ p = Player(money=100) # Basic bet p.placeBet(10) # Test placing a negative bet with pytest.raises(Exception): p.placeBet(-10) # Test betting more than we have with pytest.raises(Exception): p.placeBet(100) # Need to monkeypatch the input monkeypatch.setattr(builtins,"input",lambda _: "5") # This should call User input, which we just defined as returning 5 p.placeBet() # Get the bets bets = p.getBets() # We have had 2 bets so far assert len(bets) == 2 # Clear the bets p.clearBets() assert len(p.getBets()) == 0 # Create a machine user p = Player(money=100,strategy="bjStrategy_8deck_hitSoft17") # For now this should create an exception with pytest.raises(Exception): p.placeBet()
def test_betting(monkeypatch): """ Testing different things we can do with betting """ p = Player(money=100) # Basic bet p.placeBet(10) # Test placing a negative bet with pytest.raises(Exception): p.placeBet(-10) # Test betting more than we have with pytest.raises(Exception): p.placeBet(100) # Need to monkeypatch the input monkeypatch.setattr(builtins, "input", lambda _: "5") # This should call User input, which we just defined as returning 5 p.placeBet() # Get the bets bets = p.getBets() # We have had 2 bets so far assert len(bets) == 2 # Clear the bets p.clearBets() assert len(p.getBets()) == 0 # Create a machine user p = Player(money=100, strategy="bjStrategy_8deck_hitSoft17") # For now this should create an exception with pytest.raises(Exception): p.placeBet()
def test_payoutTable(): """ Testing payoutTable method """ # Create the table table = Table() # Create the UI ui = UI(table) # Get our rule set houseRules = ui.selectHouseRules("Mystic Lake -- Shakopee, MN") # Set up the dealer (don't waste time between cards) dealer = Dealer(houseRules=houseRules, ui=ui, dealCardDelay=0) # Set up the player player = Player(money=100, name="Bill") player2 = Player(money=100, name="Dave") table.addPlayer(player) table.addPlayer(player2) table.setDealer(dealer) ######################################### # Dealer is busted / Player 2 is busted # ######################################### # Bet player.placeBet(5) player2.placeBet(10) hand = Hand(Card("K", "Spade"), Card("Q", "Spade")) hand.addCard(Card("5", "Club")) # He busted player2.addHand(hand) # Player 1 hasn't busted hand2 = Hand(Card("J", "Spade"), Card("2", "Club")) player.addHand(hand2) # Dealer has busted hand3 = Hand(Card("5", "Diamond"), Card("7", "Club")) hand3.addCard(Card("10", "Club")) dealer.addHand(hand3) # Play it dealer.payoutTable(table) # Test it assert player.getMoney() == 105 assert player2.getMoney() == 90 ########################################### # Dealer Beats Player 1 / Pushes Player 2 # ########################################### table.reset() # Bet player.placeBet(10) player2.placeBet(20) player.clearHands() hand = Hand(Card("K", "Spade"), Card("5", "Spade")) player.addHand(hand) player2.clearHands() hand2 = Hand(Card("J", "Spade"), Card("8", "Club")) player2.addHand(hand2) # Dealer has 18 dealer.clearHands() hand3 = Hand(Card("8", "Diamond"), Card("J", "Club")) dealer.addHand(hand3) # Play it dealer.payoutTable(table) # Test it assert player.getMoney() == 95 assert player2.getMoney() == 90
def test_facilitatePlayerHand(monkeypatch): """ Test facilitatePlayerHand method """ # Create the UI ui = UI() # Get our rule set houseRules = ui.selectHouseRules("Mystic Lake -- Shakopee, MN") # Set up the dealer dealer = Dealer(houseRules=houseRules, ui=ui) ############# # Hit/Stand # ############# player = Player(money=100, name="Tim") hand = Hand(Card("2", "Club"), Card("4", "Club")) player.addHand(hand) # A little complicated player interaction here.. def playerAction(x, y): global count # Player will hit then stand if count == 0: count += 1 return "hit" else: return "stand" global count count = 0 monkeypatch.setattr(player, "selectHandAction", playerAction) # Screw the UI here.. monkeypatch.setattr(dealer.ui, "drawTable", lambda: None) dealer.facilitatePlayerHand(player, hand) # We should have 3 cards at this time assert len(hand.getCards()) == 3 ########## # Double # ########## player = Player(money=100, name="Tim") hand = Hand(Card("2", "Club"), Card("4", "Club")) player.addHand(hand) # Double will need a bet player.placeBet(20) monkeypatch.setattr(player, "selectHandAction", lambda x, y: "double") dealer.facilitatePlayerHand(player, hand) # We should have 3 cards at this time assert len(hand.getCards()) == 3 ########################### # Double not enough money # ########################### player = Player(money=100, name="Tim") hand = Hand(Card("2", "Club"), Card("4", "Club")) player.addHand(hand) # Double will need a bet player.placeBet(60) monkeypatch.setattr(player, "selectHandAction", lambda x, y: "double") with pytest.raises(Exception): dealer.facilitatePlayerHand(player, hand) # We should have 2 cards at this time assert len(hand.getCards()) == 2 ####################### # Split Unimplemented # ####################### player = Player(money=100, name="Tim") hand = Hand(Card("A", "Club"), Card("A", "Spade")) player.addHand(hand) # Double will need a bet player.placeBet(40) monkeypatch.setattr(player, "selectHandAction", lambda x, y: "split") with pytest.raises(Exception): dealer.facilitatePlayerHand(player, hand) # We should have 2 cards at this time assert len(hand.getCards()) == 2 ############### # Busted Hand # ############### player = Player(money=100, name="Tim") hand = Hand(Card("A", "Club"), Card("K", "Spade")) hand.addCard(Card("Q", "Spade")) player.addHand(hand) # Double will need a bet player.placeBet(40) monkeypatch.setattr(player, "selectHandAction", lambda x, y: "hit") dealer.facilitatePlayerHand(player, hand) # We should be busted here assert len(hand.getValue()) == 0
def test_payoutTable(): """ Testing payoutTable method """ # Create the table table = Table() # Create the UI ui = UI(table) # Get our rule set houseRules = ui.selectHouseRules("Mystic Lake -- Shakopee, MN") # Set up the dealer (don't waste time between cards) dealer = Dealer(houseRules=houseRules,ui=ui,dealCardDelay=0) # Set up the player player = Player(money=100,name="Bill") player2 = Player(money=100,name="Dave") table.addPlayer(player) table.addPlayer(player2) table.setDealer(dealer) ######################################### # Dealer is busted / Player 2 is busted # ######################################### # Bet player.placeBet(5) player2.placeBet(10) hand = Hand(Card("K","Spade"),Card("Q","Spade")) hand.addCard(Card("5","Club")) # He busted player2.addHand(hand) # Player 1 hasn't busted hand2 = Hand(Card("J","Spade"),Card("2","Club")) player.addHand(hand2) # Dealer has busted hand3 = Hand(Card("5","Diamond"),Card("7","Club")) hand3.addCard(Card("10","Club")) dealer.addHand(hand3) # Play it dealer.payoutTable(table) # Test it assert player.getMoney() == 105 assert player2.getMoney() == 90 ########################################### # Dealer Beats Player 1 / Pushes Player 2 # ########################################### table.reset() # Bet player.placeBet(10) player2.placeBet(20) player.clearHands() hand = Hand(Card("K","Spade"),Card("5","Spade")) player.addHand(hand) player2.clearHands() hand2 = Hand(Card("J","Spade"),Card("8","Club")) player2.addHand(hand2) # Dealer has 18 dealer.clearHands() hand3 = Hand(Card("8","Diamond"),Card("J","Club")) dealer.addHand(hand3) # Play it dealer.payoutTable(table) # Test it assert player.getMoney() == 95 assert player2.getMoney() == 90
def test_facilitatePlayerHand(monkeypatch): """ Test facilitatePlayerHand method """ # Create the UI ui = UI() # Get our rule set houseRules = ui.selectHouseRules("Mystic Lake -- Shakopee, MN") # Set up the dealer dealer = Dealer(houseRules=houseRules,ui=ui) ############# # Hit/Stand # ############# player = Player(money=100,name="Tim") hand = Hand(Card("2","Club"),Card("4","Club")) player.addHand(hand) # A little complicated player interaction here.. def playerAction(x,y): global count # Player will hit then stand if count == 0: count += 1 return "hit" else: return "stand" global count count = 0 monkeypatch.setattr(player,"selectHandAction",playerAction) # Screw the UI here.. monkeypatch.setattr(dealer.ui,"drawTable",lambda : None ) dealer.facilitatePlayerHand(player,hand) # We should have 3 cards at this time assert len(hand.getCards()) == 3 ########## # Double # ########## player = Player(money=100,name="Tim") hand = Hand(Card("2","Club"),Card("4","Club")) player.addHand(hand) # Double will need a bet player.placeBet(20) monkeypatch.setattr(player,"selectHandAction",lambda x,y : "double") dealer.facilitatePlayerHand(player,hand) # We should have 3 cards at this time assert len(hand.getCards()) == 3 ########################### # Double not enough money # ########################### player = Player(money=100,name="Tim") hand = Hand(Card("2","Club"),Card("4","Club")) player.addHand(hand) # Double will need a bet player.placeBet(60) monkeypatch.setattr(player,"selectHandAction",lambda x,y : "double") with pytest.raises(Exception): dealer.facilitatePlayerHand(player,hand) # We should have 2 cards at this time assert len(hand.getCards()) == 2 ####################### # Split Unimplemented # ####################### player = Player(money=100,name="Tim") hand = Hand(Card("A","Club"),Card("A","Spade")) player.addHand(hand) # Double will need a bet player.placeBet(40) monkeypatch.setattr(player,"selectHandAction",lambda x,y : "split") with pytest.raises(Exception): dealer.facilitatePlayerHand(player,hand) # We should have 2 cards at this time assert len(hand.getCards()) == 2 ############### # Busted Hand # ############### player = Player(money=100,name="Tim") hand = Hand(Card("A","Club"),Card("K","Spade")) hand.addCard(Card("Q","Spade")) player.addHand(hand) # Double will need a bet player.placeBet(40) monkeypatch.setattr(player,"selectHandAction",lambda x,y : "hit") dealer.facilitatePlayerHand(player,hand) # We should be busted here assert len(hand.getValue()) == 0