def test_isFullHouse(self): hand = Hand("AS AD AH TC TS") result = hand.is_full_house() self.assertEqual(result[0], True) self.assertListEqual(result[1], [14]) hand = Hand("2S 4D 4H 2C 4S") result = hand.is_full_house() self.assertEqual(result[0], True) self.assertListEqual(result[1], [4]) hand = Hand("TS AD AH TC KS") result = hand.is_full_house() self.assertEqual(result[0], False) self.assertEqual(result[1], None) hand = Hand("TS TD AH TC KS") result = hand.is_full_house() self.assertEqual(result[0], False) self.assertEqual(result[1], None) hand = Hand("TS TD AH KC KS") result = hand.is_full_house() self.assertEqual(result[0], False) self.assertEqual(result[1], None)
def test_hand_ace8(self): players_hand = Hand() players_hand.add_card(Card("Clubs", "A")) players_hand.add_card(Card("Diamonds", "A")) players_hand.add_card(Card("Spades", "A")) players_hand.add_card(Card("Hearts", "A")) players_hand.add_card(Card("Clubs", "K")) self.assertEqual(14, players_hand.total_value)
def test_isFourOfAKind(self): hand = Hand("AS AD AH AC KS") result = hand.is_four_of_a_kind() self.assertEqual(result[0], True) self.assertListEqual(result[1], [14]) hand = Hand("TS AD AH AC KS") result = hand.is_four_of_a_kind() self.assertEqual(result[0], False) self.assertEqual(result[1], None)
def test_isThreeOfAKind(self): hand = Hand("AS AD AC QH KS") result = hand.is_three_of_a_kind() self.assertEqual(result[0], True) self.assertListEqual(result[1], [14]) hand = Hand("TS AD TC TH KS") result = hand.is_three_of_a_kind() self.assertEqual(result[0], True) self.assertListEqual(result[1], [10]) hand = Hand("AS AD JC QH KS") result = hand.is_three_of_a_kind() self.assertEqual(result[0], False) self.assertEqual(result[1], None) hand = Hand("2S 2D JC QH QS") result = hand.is_three_of_a_kind() self.assertEqual(result[0], False) self.assertEqual(result[1], None)
def test_isStraight(self): hand = Hand("AS TD JC QH KS") result = hand.is_straight() self.assertEqual(result[0], True) self.assertListEqual(result[1], [14]) hand = Hand("9S TD JC QH 8S") result = hand.is_straight() self.assertEqual(result[0], True) self.assertListEqual(result[1], [12]) hand = Hand("AS 9D JC QH KS") result = hand.is_straight() self.assertEqual(result[0], False) self.assertEqual(result[1], None)
def test_flush(self): hand = Hand("AS TS 9S 2S 5S") result = hand.is_flush() self.assertEqual(result[0], True) self.assertListEqual(result[1], [14, 10, 9, 5, 2]) hand = Hand("TS AD AH TC KS") result = hand.is_flush() self.assertEqual(result[0], False) self.assertEqual(result[1], None) hand = Hand("TS AS AS TS KC") result = hand.is_flush() self.assertEqual(result[0], False) self.assertEqual(result[1], None)
def test_hand_initialization(self): hand = Hand() self.assertEqual(len(hand.cards), 0) self.assertEqual(hand.total_value, 0)
def test_hand_ace4(self): players_hand = Hand() players_hand.add_card(Card("Clubs", "A")) players_hand.add_card(Card("Spades", "2")) self.assertEqual(13, players_hand.total_value)
def test_hand_ace2(self): players_hand = Hand() players_hand.add_card(Card("Clubs", "K")) players_hand.add_card(Card("Hearts", "A")) self.assertEqual(21, players_hand.total_value)
def test_hand_value4(self): players_hand = Hand() players_hand.add_card(Card("Spades", "9")) players_hand.add_card(Card("Hearts", "9")) players_hand.add_card(Card("Diamonds", "9")) self.assertEqual(27, players_hand.total_value)
def test_hand_value1(self): players_hand = Hand() players_hand.add_card(Card("Clubs", "K")) players_hand.add_card(Card("Hearts", "3")) self.assertEqual(13, players_hand.total_value)
def test_isStraightFlash(self): hand = Hand("2S 3S 4S 5S 6S") result = hand.is_straight_flash() self.assertEqual(result[0], True) self.assertListEqual(result[1], [6]) hand = Hand("TS JS QS KS AS") result = hand.is_straight_flash(); self.assertEqual(result[0], True) self.assertListEqual(result[1], [14]) # hand is not sorted hand = Hand("JS AS QS TS KS") result = hand.is_straight_flash(); self.assertEqual(result[0], True) self.assertListEqual(result[1], [14]) hand = Hand("TS JS QH KH AH") result = hand.is_straight_flash(); self.assertEqual(result[0], False) self.assertEqual(result[1], None) hand = Hand("2S 3S 4S 5S 7S") result = hand.is_straight_flash() self.assertEqual(result[0], False) self.assertEqual(result[1], None) hand = Hand("2S TD JD QS KS") result = hand.is_straight_flash() self.assertEqual(result[0], False) self.assertEqual(result[1], None)
def test_isPair(self): hand = Hand("QS AD 9C QH KS") result = hand.is_pair() self.assertEqual(result[0], True) self.assertEqual(result[1], [12, 14, 13, 9]) hand = Hand("QS AD QC QH 9S") result = hand.is_pair() self.assertEqual(result[0], True) self.assertEqual(result[1], [12, 14, 12, 9]) hand = Hand("3S 3D 3C 3H 9S") result = hand.is_pair() self.assertEqual(result[0], True) self.assertEqual(result[1], [3, 9, 3, 3]) hand = Hand("2S 2D 3C 3H 9S") result = hand.is_pair() self.assertEqual(result[0], True) self.assertEqual(result[1], [3, 9, 2, 2]) hand = Hand("3S 3D 2C 2H 9S") result = hand.is_pair() self.assertEqual(result[0], True) self.assertEqual(result[1], [3, 9, 2, 2]) hand = Hand("AS 9D 3C QH KS") result = hand.is_pair() self.assertEqual(result[0], False) self.assertEqual(result[1], None)
def test_isTwoPairs(self): hand = Hand("AS AD QC QH KS") result = hand.is_two_diff_pairs() self.assertEqual(result[0], True) self.assertEqual(result[1], [14, 12, 13]) hand = Hand("3S 3D 2C 2H KS") result = hand.is_two_diff_pairs() self.assertEqual(result[0], True) self.assertEqual(result[1], [3, 2, 13]) hand = Hand("AS AD JC QH KS") result = hand.is_two_diff_pairs() self.assertEqual(result[0], False) self.assertEqual(result[1], None) #this is ok since this will be full house, which is greater then two pairs hand = Hand("AS AD AC KH KS") result = hand.is_two_diff_pairs() self.assertEqual(result[0], True) self.assertListEqual(result[1], [14, 13, 14]) hand = Hand("TD TC 2D 2H AC") result = hand.is_two_diff_pairs() self.assertEqual(result[0], True) self.assertListEqual(result[1], [10, 2, 14]) hand = Hand("TS TH 3S 3D 2S") result = hand.is_two_diff_pairs() self.assertEqual(result[0], True) self.assertListEqual(result[1], [10, 3, 2])
def test_hand_ace5(self): players_hand = Hand() players_hand.add_card(Card("Clubs", "A")) players_hand.add_card(Card("Diamonds", "A")) self.assertEqual(12, players_hand.total_value)
from main import hands, count_hands, Hand, score_hands, dealer_wins for x in range(100): hand = hands() counted = count_hands(hand) score = score_hands(counted) hand = Hand(hand, counted, score) print("You - " + str(hand['player']['hand'])) print("Dealer - " + str(hand['dealer']['hand'])) if dealer_wins(hand): print("You lose to " + str(hand['dealer']['text'])) else: print("You win with " + str(hand['player']['text']))
def test_Deck(self, list2=None, list1=None): objDeck = Deck() # test that new deck is 52 cards deckOfCards = objDeck.cardset assert len(deckOfCards) == 52 # test that values are in correct sorted location sortedDeck = objDeck.sort() print("sortedCards ", sortedDeck) assert sortedDeck[0:1][0:1] == [(1, 1)] assert sortedDeck[0:10][9:10] == [(1, 10)] assert sortedDeck[0:13][12:13] == [(1, 13)] assert sortedDeck[0:26][25:26] == [(2, 13)] assert sortedDeck[0:39][38:39] == [(3, 13)] assert sortedDeck[0:52][51:52] == [(4, 13)] # shuffle deck shuffledCards = objDeck.shuffle() print("shuffledCards ", shuffledCards) list1 = list(shuffledCards) # test second shuffle secondShuffle = objDeck.shuffle() print('secondShuffle ', secondShuffle) list2 = list(secondShuffle) # shuffles should be unique (is it even possible to have back to back shuffles the same, I don't think so) isSame = functools.reduce(lambda x, y: x and y, map(lambda p, q: p == q, list1, list2), True) assert isSame == False # create hand playerHand = Hand() # initial hand should always score to zero assert playerHand.gettotal() == 0 # add card from shuffled deck playerCard = shuffledCards.pop(0) playerHand.add_card(playerCard) # total hand playerHand.totalhand() # added first card implies hand value will be greater than 0 assert playerHand.gettotal() > 0 # size of shuffledCards should now be 51 assert len(shuffledCards) == 51 # test method add_card to verify hand is in fact 35 newPlayer1Hand = Hand() newPlayer1Hand.add_card((4, 2)) newPlayer1Hand.add_card((1, 11)) newPlayer1Hand.add_card((4, 4)) newPlayer1Hand.totalhand() assert newPlayer1Hand.gettotal() == 35 # manually create another hand that totals 37 newPlayer2Hand = Hand() newPlayer2Hand.add_card((4, 2)) newPlayer2Hand.add_card((3, 7)) newPlayer2Hand.add_card((1, 8)) newPlayer2Hand.totalhand() assert newPlayer2Hand.gettotal() == 37 # test for Winner class; winner should be hand two winner = Winner(newPlayer1Hand.gettotal(), newPlayer2Hand.gettotal()) assert winner.getwinner() == 'player2 wins' # test conversion method where suits = [1, 2, 3, 4] = ['Spades', 'Diamonds','Hearts','Clubs'] newPlayer1Hand.conversion() assert newPlayer1Hand.playercards[1][1] == 'Jack' assert newPlayer1Hand.playercards[0][0] == 'Clubs' assert newPlayer1Hand.playercards[1][0] == 'Spades' assert newPlayer1Hand.playercards[2][0] == 'Clubs'