def test_Game(self): """Test Game class""" players = [ Player(name="Player One", stack=1000), Player(name="Player Two", stack=1000), Player(name="Player Three", stack=1000) ] table = Table(players = players) structure = Structure(Structure.LIMIT, ante=5, blinds=[10]) game = Game(table, structure, console=self.console) self.assertIsNotNone(game) self.assertEqual(game.table, table) self.assertEqual(game.structure, structure) # Default MessageHander should be created. self.assertIsNotNone(game.message_handler) game.message("Test message") game.debug("Test debug message") # Simulate play_hand() hand_state = HandState(table, game.message_handler) game.antes(hand_state) self.assertEqual(hand_state.pot.amount, 15) game.action_to_left_of_dealer(hand_state) betting_round = hand_state.get_current_betting_round() self.assertIsInstance(betting_round, BettingRound) self.assertIsInstance(betting_round.get_action_player(), Player) game.blinds(hand_state) self.assertEqual(betting_round.total_pot(), 25) # Antes + 10 blind game.deal_hands(hand_state) for player in players: self.assertEqual(len(player._hand), 5) # Simulate betting_round() self.assertFalse(betting_round.is_pot_good()) action_request = game._get_action_request(hand_state) self.assertIsInstance(action_request, ActionRequest) # Should be call of blind self.assertTrue(action_request.is_call_request()) self.assertEqual(action_request.amount, 10) self.assertEqual(action_request.raise_amount, 20) # Fold UTG betting_round.process_action(Action.new_fold()) self.assertFalse(betting_round.is_pot_good()) # Should be same request as before action_request2 = game._get_action_request(hand_state) self.assertIsInstance(action_request2, ActionRequest) self.assertTrue(action_request2.is_call_request()) self.assertEqual(action_request2.amount, 10) self.assertEqual(action_request2.raise_amount, 20) # Now raise betting_round.process_action(Action.new_raise(20)) self.assertFalse(betting_round.is_pot_good()) # Action back on blind action_request3 = game._get_action_request(hand_state) self.assertIsInstance(action_request3, ActionRequest) self.assertTrue(action_request3.is_call_request()) self.assertEqual(action_request3.amount, 10) self.assertEqual(action_request3.raise_amount, 20) betting_round.process_action(Action.new_call(10)) self.assertTrue(betting_round.is_pot_good()) game.pot_to_high_hand(hand_state)
def test_HandState(self): """Test HandState class""" players = [ Player(stack=500), Player(stack=100), Player(stack=1000), Player(stack=700) ] table = Table() table.seat_players(players, in_order=True) message_handler = MessageHandler(table, self.console) hand_state = HandState(table, message_handler) self.assertIsNotNone(hand_state) self.assertEqual(hand_state.table, table) for player in players: self.assertIsNotNone(player._hand) hand_state.deal_cards(5) for player in players: self.assertEqual(len(player._hand), 5) betting_round = hand_state.new_betting_round() self.assertIsNotNone(betting_round) self.assertEqual(hand_state.get_current_betting_round(), betting_round) self.assertEqual(len(hand_state.betting_rounds), 1) betting_round2 = hand_state.new_betting_round() self.assertIsNotNone(betting_round2) self.assertEqual(hand_state.get_current_betting_round(), betting_round2) self.assertEqual(len(hand_state.betting_rounds), 2) self.assertIsNotNone(hand_state.dump_to_string())