def test_basic_strat_split_nonace(self): """Test split non-ace """ strategy = BasicStrategy(self.deck) player_hand = Hand() player_hand.add_card(Card("Spades", "3")) player_hand.add_card(Card("Clubs", "3")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "2")) dealer_hand.add_card(Card("Clubs", "3")) is_playing = strategy.play_hand(SPLIT, player_hand, dealer_hand) self.assertEqual(len(strategy.split_hands), 2) self.assertEqual(is_playing, True)
def test_basic_strat_split(self): """Test split """ strategy = BasicStrategy(self.deck) player_hand = Hand() player_hand.add_card(Card("Spades", "A")) player_hand.add_card(Card("Clubs", "A")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "2")) dealer_hand.add_card(Card("Clubs", "9")) cont_playing = strategy.play_hand(SPLIT, player_hand, dealer_hand) self.assertEqual(len(strategy.split_hands), 2) self.assertEqual(cont_playing, True) self.assertEqual(strategy.cont_split, False)
def test_calculate_earnings(self): d = Deck(4) d.shuffle() d.cut() h1 = Hand() h1.add_card(Card("Spades", "2")) h1.add_card(Card("Clubs", "2")) h1.add_bet(5.0) h2 = Hand() h2.add_card(Card("Spades", "2")) h2.add_card(Card("Clubs", "A")) h2.add_bet(5.0) h3 = Hand() h3.add_card(Card("Spades", "2")) h3.add_card(Card("Clubs", "J")) h3.add_bet(5.0) h4 = Hand() h4.add_card(Card("Spades", "2")) h4.add_card(Card("Clubs", "Q")) h4.add_bet(5.0) h5 = Hand() h5.add_card(Card("Spades", "2")) h5.add_card(Card("Clubs", "K")) h5.add_bet(5.0) strategy = BasicStrategy(d) game = Game(d, strategy) earnings = game.calculate_earnings(h1, WIN, False) self.assertEqual(earnings, 5.0) game = Game(d, strategy) earnings = game.calculate_earnings(h1, LOSS, False) self.assertEqual(earnings, 5.0) game = Game(d, strategy) earnings = game.calculate_earnings(h1, WIN, True) self.assertEqual(earnings, 5.0) game = Game(d, strategy) earnings = game.calculate_earnings(h2, WIN, False) self.assertEqual(earnings, 7.5) game = Game(d, strategy) earnings = game.calculate_earnings(h3, WIN, False) self.assertEqual(earnings, 7.5) game = Game(d, strategy) earnings = game.calculate_earnings(h4, WIN, False) self.assertEqual(earnings, 7.5) game = Game(d, strategy) earnings = game.calculate_earnings(h5, WIN, False) self.assertEqual(earnings, 7.5)
def test_calculate_result_hit(self): """Test result for normal stand """ d = Deck(4) d.shuffle() d.cut() player_hand = Hand() player_hand.add_card(Card("Spades", "Q")) player_hand.add_card(Card("Clubs", "2")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "10")) dealer_hand.add_card(Card("Hearts", "7")) strategy = BasicStrategy(d) game = Game(d, strategy) game.calculate_results(player_hand, dealer_hand) self.assertGreater(len(player_hand.cards), 2)
def test_calculate_result_split_noneace(self): """Test result for split without aces """ d = Deck(4) d.shuffle() d.cut() player_hand = Hand() player_hand.add_card(Card("Spades", "2")) player_hand.add_card(Card("Clubs", "2")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "10")) dealer_hand.add_card(Card("Hearts", "3")) strategy = BasicStrategy(d) game = Game(d, strategy) game.calculate_results(player_hand, dealer_hand) game.display_results() self.assertGreaterEqual(len(strategy.split_hands), 2) self.assertEqual( game.game_info["losses"] + game.game_info["wins"] + game.game_info["ties"], 2)
def test_calculate_result_split_ace(self): """Test result for split """ d = Deck(4) d.shuffle() d.cut() player_hand = Hand() player_hand.add_card(Card("Spades", "A")) player_hand.add_card(Card("Clubs", "A")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "10")) dealer_hand.add_card(Card("Hearts", "3")) strategy = BasicStrategy(d) game = Game(d, strategy) game.calculate_results(player_hand, dealer_hand) game.display_results() self.assertGreaterEqual(len(strategy.split_hands), 2) self.assertEqual(len(strategy.split_hands[0].cards), 2) self.assertEqual(len(strategy.split_hands[1].cards), 2)
def setUpClass(self): self.deck = Deck(1) self.deck.shuffle() self.deck.cut() self.strategy = BasicStrategy(self.deck)
class TestBasicStrategy(TestCase): """Test basic strat """ @classmethod def setUpClass(self): self.deck = Deck(1) self.deck.shuffle() self.deck.cut() self.strategy = BasicStrategy(self.deck) def test_basic_strat_normal_hit(self): """Test with hit scenario """ player_hand = Hand() player_hand.add_card(Card("Spades", "4")) player_hand.add_card(Card("Clubs", "4")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "Q")) dealer_hand.add_card(Card("Clubs", "10")) self.strategy.play(player_hand, dealer_hand) self.assertGreater(len(player_hand.cards), 2) def test_basic_strat_normal_hit_two(self): """Test with hit scenario 2 (border edge of chart) """ player_hand = Hand() player_hand.add_card(Card("Spades", "J")) player_hand.add_card(Card("Clubs", "6")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "2")) dealer_hand.add_card(Card("Clubs", "7")) self.strategy.play(player_hand, dealer_hand) self.assertGreater(len(player_hand.cards), 2) def test_basic_strat_normal_stand(self): """Test with stand scenario (border edge of chart) """ player_hand = Hand() player_hand.add_card(Card("Spades", "J")) player_hand.add_card(Card("Clubs", "6")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "2")) dealer_hand.add_card(Card("Clubs", "6")) self.strategy.play(player_hand, dealer_hand) self.assertEqual(len(player_hand.cards), 2) def test_basic_strat_split(self): """Test split """ strategy = BasicStrategy(self.deck) player_hand = Hand() player_hand.add_card(Card("Spades", "A")) player_hand.add_card(Card("Clubs", "A")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "2")) dealer_hand.add_card(Card("Clubs", "9")) cont_playing = strategy.play_hand(SPLIT, player_hand, dealer_hand) self.assertEqual(len(strategy.split_hands), 2) self.assertEqual(cont_playing, True) self.assertEqual(strategy.cont_split, False) def test_basic_strat_split_nonace(self): """Test split non-ace """ strategy = BasicStrategy(self.deck) player_hand = Hand() player_hand.add_card(Card("Spades", "3")) player_hand.add_card(Card("Clubs", "3")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "2")) dealer_hand.add_card(Card("Clubs", "3")) is_playing = strategy.play_hand(SPLIT, player_hand, dealer_hand) self.assertEqual(len(strategy.split_hands), 2) self.assertEqual(is_playing, True) def test_basic_strat_double_1(self): """Test double down 1 """ player_hand = Hand() player_hand.add_bet(2.0) player_hand.add_card(Card("Spades", "A")) player_hand.add_card(Card("Clubs", "2")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "2")) dealer_hand.add_card(Card("Clubs", "5")) self.strategy.play(player_hand, dealer_hand) self.assertGreater(len(player_hand.cards), 2) self.assertEqual(player_hand.bet, 4.0) def test_basic_strat_double_2(self): """Test double down 2 """ player_hand = Hand() player_hand.add_bet(2.0) player_hand.add_card(Card("Spades", "A")) player_hand.add_card(Card("Clubs", "3")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "2")) dealer_hand.add_card(Card("Clubs", "5")) self.strategy.play(player_hand, dealer_hand) self.assertGreater(len(player_hand.cards), 2) self.assertEqual(player_hand.bet, 4.0) def test_basic_strat_double_hit(self): """Test double down 2 """ player_hand = Hand() player_hand.add_bet(2.0) player_hand.add_card(Card("Spades", "A")) player_hand.add_card(Card("Clubs", "3")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "2")) dealer_hand.add_card(Card("Clubs", "4")) self.strategy.play(player_hand, dealer_hand) self.assertGreater(len(player_hand.cards), 2) self.assertEqual(player_hand.bet, 2.0) def test_basic_strat_scen_1(self): """Test basic scenario, A, 3, dealer: 6, 10 """ player_hand = Hand() player_hand.add_bet(2.0) player_hand.add_card(Card("Spades", "A")) player_hand.add_card(Card("Clubs", "3")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "6")) dealer_hand.add_card(Card("Clubs", "10")) self.strategy.play(player_hand, dealer_hand) self.assertGreater(len(player_hand.cards), 2) def test_basic_strat_scen_2(self): """Test basic scenario, A, 3, dealer: 6, 10 """ player_hand = Hand() player_hand.add_bet(2.0) player_hand.add_card(Card("Spades", "A")) player_hand.add_card(Card("Clubs", "7")) dealer_hand = Hand() dealer_hand.add_card(Card("Spades", "6")) dealer_hand.add_card(Card("Clubs", "5")) self.strategy.play(player_hand, dealer_hand) self.assertGreater(len(player_hand.cards), 2) self.assertEqual(player_hand.bet, 4.0)