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_hand_add_bet(self): """Test adding bet """ h = Hand() h.add_bet(10) self.assertEqual(h.bet, 10) payout_ratio = 0.5 h.add_bet(10 + (10 * payout_ratio)) self.assertEqual(h.bet, 15)
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_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_calculate_result_double(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", "1")) player_hand.add_bet(5.0) 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) self.assertGreater(len(player_hand.cards), 2) self.assertEqual(player_hand.bet, 10.0)