def test_make_bet_whole_budget(self, _print_mock): budget = 2 ai_player = AiPlayer(_, budget) ai_player.make_bet() self.assertEqual(ai_player.current_bet, budget)
def test_make_bet(self, _print_mock): budget = 100 ai_player = AiPlayer(_, budget) ai_player.make_bet() self.assertIn(ai_player.current_bet, range(2, budget + 1))
def main_game(): players = [Player('Bob', 500), AiPlayer('Sam', 500)] dealer = AiPlayer('Dealer', 5000) game = Game(players, dealer) print('\nWelcome!\n') game.game_loop() print('\nThanks for playing!')
def test_game_loop_out_of_budget(self, _print_mock, single_game_mock): budget = 500 player = Player('Bob', budget) players = [player] dealer = AiPlayer('Dealer', 5000) def single_game(self): for player in self.players: player.budget = 0 single_game_mock.side_effect = single_game game = Game(players, dealer) game.game_loop() self.assertFalse(game.players)
def test_game_loop_no_continue(self, _print_mock, get_answer_mock, single_game_mock): budget = 500 player = Player('Bob', budget) players = [player] dealer = AiPlayer('Dealer', 5000) def single_game(self): for player in self.players: player.budget = 0 single_game_mock.side_effect = single_game get_answer_mock.return_value = 'n' game = Game(players, dealer) game.game_loop() self.assertFalse(game.players)
def test_make_move(self): hit = 'hit' stand = 'stand' moves = [] ai_player = AiPlayer(_, _) value = 5 ai_player.cards = [Card(_, [value], _, exposed=True)] moves.append(ai_player.make_move()) value = 18 ai_player.cards = [Card(_, [value], _, exposed=True)] moves.append(ai_player.make_move()) self.assertEqual(moves, [hit, stand])
def test_player_loses(self, _print_mock, ai_player_make_move_mock, player_make_move_mock, player_make_bet_mock, deal_start_cards_mock): player_cards = [ Card('One', [1], '♣', exposed=True), Card('One', [1], '♦', exposed=True), ] dealer_cards = [ Card('Ten', [10], '♣', exposed=True), Card('Ten', [10], '♦', exposed=False), ] def deal(self): for player in self.players: player.cards.extend(player_cards) self.dealer.cards.extend(dealer_cards) deal_start_cards_mock.side_effect = deal budget = 500 player = Player('Bob', budget) players = [player] dealer = AiPlayer('Dealer', 5000) bet = 100 def make_bet(self): self.current_bet = bet player_make_bet_mock.side_effect = make_bet stand = 'stand' player_make_move_mock.return_value = stand ai_player_make_move_mock.return_value = stand game = Game(players, dealer) game.single_game() self.assertEqual(player.budget, budget - bet)