def test_add_card(self): hand = Hand() card = Card(1, 'Hearts') hand.add_card(card) self.assertEqual(len(hand.cards), 1)
def test_hand_class(): hand1 = Hand([c0, c10]) hand2 = Hand([c11, c4, c5]) hand3 = Hand([c0, c0, c12]) hand4 = Hand([c0, c0, c0]) print("Testing random hands") hand_class_test(hand1, 21, True, True) hand_class_test(hand2, 21, False, False) hand_class_test(hand3, 12, False, False) hand_class_test(hand4, 13, True, False) print("Testing if Hand class can accept single card") hand5 = Hand([c0]) hand_class_test(hand5, 11, True, False) print("Testing if Hand class can add card that makes blackjack") hand5.add_card(c10) hand_class_test(hand5, 21, True, True) print("Testing if Hand class can add card that gives 21 but not BJ") hand6 = Hand([c4, c5]) hand_class_test(hand6, 11, False, False) hand6.add_card(c11) hand_class_test(hand6, 21, False, False)
class Player(): def __init__(self, deck): self.my_hand = Hand() self.my_chips = Chips() self.deck = deck def __str__(self): return "Hand {1}: {0}".format([ "{} of {}".format(x.suit, {k for k, v in x.rank.items()}) for x in self.my_hand.cards ], self.__class__.__name__) def hit(self): card = self.deck.deal() if "ase" in card.rank: card.rank["ase"] = self.my_hand.adjas_of_ase() self.my_hand.values += [x for x in card.rank.values()][0] self.my_hand.add_card(card) print(card) def begin(self): self.my_hand.add_card(self.deck.deal()) self.my_hand.add_card(self.deck.deal()) for ase in self.my_hand.cards: if [k for k in ase.rank if k is "ase"]: ase.rank["ase"] = self.my_hand.adjas_of_ase() self.my_hand.values = sum( [sum({v for k, v in x.rank.items()}) for x in self.my_hand.cards])
class Dealer(Player): def __init__(self, deck): self.my_hand = Hand() self.deck = deck self.i = 1 def __str__(self): return "Hand {1}: {0}".format( ["{} of {}".format( self.my_hand.cards[x].suit, {k for k, v in self.my_hand.cards[x].rank.items()}) for x in range(0,self.i)], self.__class__.__name__) def hit(self): card = self.deck.deal() print(card) self.i += 1 if "ase" in card.rank: card.rank["ase"] = self.my_hand.adjas_of_ase() self.my_hand.values += [x for x in card.rank.values()][0] self.my_hand.add_card(card) def show_2nd_card(self): self.i += 1 def take_bet(self, player, bet): player.my_chips.total -= bet player.my_chips.bet += bet
def test_are_all_cards_of_this_val_out(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.ORANGE, 1) c3 = Card(Colour.YELLOW, 1) c4 = Card(Colour.GREEN, 1) c5 = Card(Colour.BLUE, 1) c6 = Card(Colour.PURPLE, 1) c7 = Card(Colour.PURPLE, 2) c8 = Card(Colour.GREEN, 2) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) h1.add_card(c7) h1.add_card(c8) slot_1 = Slot() slot_2 = Slot() slot_1.play_card(c1, h1) slot_1.play_card(c2, h1) slot_1.play_card(c3, h1) slot_1.play_card(c4, h2) slot_1.play_card(c5, h2) slot_1.play_card(c6, h2) slot_2.play_card(c7, h1) slot_2.play_card(c8, h1) slots = [slot_1, slot_2] self.assertTrue(self.slot.are_all_cards_of_this_val_out(1, slots)) self.assertFalse(self.slot.are_all_cards_of_this_val_out(2, slots)) self.assertFalse(self.slot.are_all_cards_of_this_val_out(7, slots))
def _init_hands(self, deck): player_hand = Hand() house_hand = Hand() for _ in range(0, 2): player_hand.add_card(deck.draw_card()) house_hand.add_card(deck.draw_card()) return player_hand, house_hand
def test_three_kings_is_bust(self): hand = Hand() hand.add_card(Card(13, Card.SPADES)) hand.add_card(Card(13, Card.HEARTS)) hand.add_card(Card(13, Card.CLUBS)) self.assertTrue(hand.is_bust())
class Player: def __init__(self, name, chips=100): self.name = name self.chips = chips self.hand = Hand() self.bet = 0 def add_card(self, card): self.hand.add_card(card) def place_bet(self): while True: try: bet = int( input( 'You can bet up to {} chips, how much will you bet {}? ' .format(self.chips, self.name))) except: print('Input a number please') continue else: if self.chips < bet and bet > 0: continue break self.chips -= bet self.bet = bet def __str__(self): return '{}; Chips: {}; Bet: {}; Cards: {}'.format( self.name, self.chips, self.bet, self.hand)
def add_hand(self): o_hand = Hand(0) a_card = self.deck.get_card() b_card = self.deck.get_card() o_hand.add_card(a_card) o_hand.add_card(b_card) self.hands.append(o_hand)
def game(): global playing while True: print("WELCOME TO BLACKJACK") deck = Deck() deck.shuffle() player_hand = Hand() player_hand.add_card(deck.deal()) player_hand.add_card(deck.deal()) dealer_hand = Hand() dealer_hand.add_card(deck.deal()) dealer_hand.add_card(deck.deal()) player_chips = Chips() take_bet(player_chips) show_some(player_hand, dealer_hand) while playing: hit_or_stand(deck, player_hand) show_some(player_hand, dealer_hand) if player_hand.value > 21: player_busts(player_hand, dealer_hand, player_chips) break if player_hand.value <= 21: while dealer_hand.value < 17: hit(deck, dealer_hand) show_all(player_hand, dealer_hand) if dealer_hand.value > 21: dealer_busts(player_hand, dealer_hand, player_chips) elif dealer_hand.value > player_hand.value: dealer_wins(player_hand, dealer_hand, player_chips) elif dealer_hand.value < player_hand.value: player_wins(player_hand, dealer_hand, player_chips) else: push(player_hand, dealer_hand) print('\n Player total chips are at: {}'.format(player_chips.total)) new_game = input("Would you like to play another hand? y/n") if new_game[0].lower() == 'y': playing = True continue else: print('Thank you for playing!') break
def test_hand_count2(self): hand = Hand() hand.add_card(Card(14, 'Clubs')) hand.add_card(Card(12, 'Spades')) total = hand.value() self.assertEqual(total, 21)
def deal_hand(self): '''deal a hand of two cards''' try: hand = Hand() for i in range(2): hand.add_card(self.cards[0]) self.cards.pop(0) return hand except IndexError: raise OutOfCardsException
def start_game(playing): while True: print('WELCOME TO BLACKJACK') deck = Deck(suits, ranks) deck.shuffle() player_hand = Hand(values) player_hand.add_card(deck.deal()) player_hand.add_card(deck.deal()) dealer_hand = Hand(values) dealer_hand.add_card(deck.deal()) dealer_hand.add_card(deck.deal()) player_chips = Chip() player_chips.take_bet() player = Player(player_hand, dealer_hand, player_chips.bet) player.show_some() while playing: player.hit_or_stand(deck, player_hand) player.show_some() if player_hand.value > 21: player.player_busts(player_chips) if player_hand.value <= 21: while dealer_hand.value < player_hand.value: player.dealer_hit(deck) player.show_all() if dealer_hand.value > 21: player.dealer_busts(player_chips) elif dealer_hand.value > player_hand.value: player.dealer_wins(player_chips) elif dealer_hand.value < player_hand.value: player.player_wins(player_chips) else: player.push() print('\nPlayer total chips are at: {}'.format(player_chips.total)) new_game = input('Would you like to play another game?(y/n) ') if new_game.lower() == 'y': playing = True continue else: print('You brings {} chips'.format(player_chips.total)) break break
class TestHand(unittest.TestCase): """ Submodule for unittests, derives from unittest.TestCase """ def setUp(self): """ Create object for all tests """ name = "Patrik" hand = ["Ace of Heart", "2 of Spades", "King of Clover", "10 of Diamond"] self.hand = Hand(name, hand) def tearDown(self): """ Remove dependencies after test """ self.hand = None def test_name(self): """ Check player name """ self.assertEqual(self.hand.name, "Patrik") def test_player_hand(self): """ Check player hand """ self.assertEqual(self.hand.hand[0], "Ace of Heart") self.assertEqual(self.hand.hand[3], "10 of Diamond") def test_picking_up_cards(self): """ Test so that picked up cards appends to the hand 5 of Diamond should be first of the new hand """ picked_cards = ["5 of Diamond", "King of Heart", "3 of Spades"] self.assertEqual(len(self.hand.hand), 4) self.hand.add_card(picked_cards) self.assertEqual(len(self.hand.hand), 7) self.assertEqual(self.hand.hand[0], "5 of Diamond") def test_played_card(self): """ Test playing card is the top card of the hand """ self.assertEqual(len(self.hand.hand), 4) played_card = self.hand.remove_card() self.assertEqual(len(self.hand.hand), 3) self.assertEqual(played_card, "10 of Diamond") def test_cards_remaining(self): """ After playing a card test so remain cards is correct """ self.hand.remove_card() self.assertEqual(self.hand.remaining_cards(), str(len(self.hand.hand)))
def test_is_this_card_out(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 2) c3 = Card(Colour.BLUE, 3) c4 = Card(Colour.GREEN, 1) c5 = Card(Colour.BLUE, 4) c6 = Card(Colour.PURPLE, 7) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) slot_1 = Slot() slot_2 = Slot() slot_1.play_card(c1, h1) slot_1.play_card(c4, h2) slot_2.play_card(c2, h1) slot_2.play_card(c5, h2) slots = [slot_1, slot_2] self.assertTrue(self.slot.is_this_card_out(1, Colour.RED, slots)) self.assertTrue(self.slot.is_this_card_out(1, Colour.GREEN, slots)) self.assertFalse(self.slot.is_this_card_out(3, Colour.BLUE, slots)) self.assertFalse(self.slot.is_this_card_out(7, Colour.PURPLE, slots))
def analyze_hand(player_hand, dealer_hand, wager, shoe, blackjack_value, dealer_hits_on_soft_17, double_after_split, surrender_allowed, double_allowed): total_wager = 0 hand_wager = wager winnings = 0 dealer_hand.dealer_hit(shoe, replace=True, hit_on_soft_17=dealer_hits_on_soft_17) choice = '' while choice not in ('stand', 'surrender'): if player_hand.value == 'BUST': break is_double = (len(player_hand.cards) != len(set(player_hand.cards))) and len(player_hand.cards) == 2 if player_hand.total == 3: print(player_hand, player_hand.total) choice = player_choice.get_player_decision(player_hand.total, dealer_hand.cards[0], player_hand.soft_aces > 0, is_double, dealer_hits_on_soft_17) # Surrender Choice if choice in ('RP', 'RS', 'RH') and surrender_allowed: return wager, wager / 2 # Split Choice if choice in ('P', 'PH', 'RP'): if double_after_split or choice == 'P' or choice == 'RP': new_hand = Hand(player_hand.remove_card()) new_hand.add_card(shoe.get_random_card()) player_hand.add_card(shoe.get_random_card()) hand1_wager, hand1_winnings = analyze_hand(new_hand, dealer_hand, wager, shoe, blackjack_value, dealer_hits_on_soft_17, double_after_split, surrender_allowed, double_allowed) total_wager += hand1_wager winnings += hand1_winnings continue # Double Choice if choice in ('DH', 'DS') and double_allowed: player_hand.add_card(shoe.get_random_card()) hand_wager += wager break if choice in ('H', 'DH', 'PH', 'RH'): player_hand.add_card(shoe.get_random_card()) continue # Otherwise, stand break winnings += hand_wager * hand_comparison(player_hand, dealer_hand, True, True, blackjack_value) total_wager += hand_wager return total_wager, winnings
class TestHand(unittest.TestCase): def setUp(self): self.hand_1 = Hand(1) self.hand_2 = Hand(2) def test_add(self): c1 = Card(Colour.RED, 10) c2 = Card(Colour.BLUE, 1) c3 = Card(Colour.GREEN, 5) self.hand_1.add_card(c1) self.hand_1.add_card(c2) self.hand_1.add_card(c3) self.assertTrue(c1 in self.hand_1.cards) self.assertTrue(c2 in self.hand_1.cards) self.assertTrue(c3 in self.hand_1.cards) def test_add_many(self): c1 = Card(Colour.RED, 10) c2 = Card(Colour.BLUE, 1) c3 = Card(Colour.GREEN, 5) l = [c1, c2, c3] self.hand_1.add_cards(l) self.assertTrue(c1 in self.hand_1.cards) self.assertTrue(c2 in self.hand_1.cards) self.assertTrue(c3 in self.hand_1.cards) def test_remove(self): c1 = Card(Colour.RED, 10) c2 = Card(Colour.BLUE, 1) c3 = Card(Colour.GREEN, 5) self.hand_1.add_card(c1) self.hand_1.add_card(c2) self.hand_1.add_card(c3) self.hand_1.remove_card(c1) self.assertFalse(c1 in self.hand_1.cards) self.assertTrue(c2 in self.hand_1.cards) self.assertTrue(c3 in self.hand_1.cards) def test_remove_card_not_in_hand(self): c1 = Card(Colour.RED, 10) c2 = Card(Colour.BLUE, 1) c3 = Card(Colour.GREEN, 5) self.hand_1.add_card(c1) self.hand_1.add_card(c2) self.hand_1.remove_card(c3) self.assertTrue(c1 in self.hand_1.cards) self.assertTrue(c2 in self.hand_1.cards) self.assertFalse(c3 in self.hand_1.cards)
def main(): """ Reads the input from stdin. Outputs to stdout. """ trump = sys.stdin.readline().strip() my_hand = Hand(trump[0].lower()) line = 0 while line < 5: card = sys.stdin.readline() my_hand.add_card(card[0], card[1]) line += 1 my_hand.sort_hand() print(trump) print(my_hand)
def test_check_winner_neither_slots_full(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 2) c4 = Card(Colour.GREEN, 10) c5 = Card(Colour.RED, 4) h1.add_card(c1) h1.add_card(c2) h2.add_card(c4) h2.add_card(c5) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.assertEqual(self.slot.check_winner(None), 0)
def deal_initial_hands(self): """Deals hands for all players in the game. Deal two cards to each bet box starting from the dealer's left, followed by one for the dealer. Note that this is NOT hole card play, where another card is dealt face down so that the game can end immediately if the dealer has a blackjack.""" num_cards = 2 for player in self.players: new_hand = Hand() for i in range(num_cards): new_card = self.draw_card() new_hand.add_card(new_card) player.assign_hand(new_hand) UI.deal_hand(player, new_hand) dealer_hand = Hand([self.draw_card()]) self.dealer.assign_hand(dealer_hand)
def main(): while True: print("Welcome to Black Jack!") """ Create & shuffle the deck, deal two cards to each player """ deck = Deck() deck.shuffle() player = Hand() # player's hand dealer = Hand() # dealer's hand for i in range(0, 2): player.add_card(deck.deal()) dealer.add_card(deck.deal()) """ Prompt the Player for their bet and set up the Player's chips """ chips_info = take_bet() chips = Chips(chips_info[0], chips_info[1]) show_some(player, dealer) while playing: hit_or_stand(deck, player) show_some(player, dealer) if player.value > 21: player_loses(chips) break if player.value <= 21: # If Player hasn't busted, play Dealer's hand until Dealer reaches or exceeds 17 while dealer.value < 17: hit(deck, dealer) show_all(player, dealer) """ Run different winning scenarios """ if dealer.value > 21 or player.value > dealer.value: player_wins(chips) elif player.value < dealer.value: player_loses(chips) print("You now have {} chips.\n").format(chips.total) play_again = raw_input( "Would you like to play again? yes/no \n").lower() if play_again != "yes": print("Thanks for playing!\n") break
def main(): deck = Deck() #print(deck) deck.shuffle() player_hand = Hand() for i in range(1, 5): print(player_hand.add_card(deck.pick_card()).number.value) print(player_hand.count())
def game_result(hold_string): global hold_cards global game_hand global game_deck print("Global card list:\t", game_hand) local_list = Hand() local_deck = copy.deepcopy(game_deck) hold_cards = str(hold_string).split('-') hold_cards_display = [] for i in range(0, 5): if hold_cards[i] == 't': local_list.add_card(game_hand.cards[i]) hold_cards_display.append(game_hand.cards[i]) else: #== 'f' card_to_add = local_deck.draw_card() local_list.add_card(card_to_add) hold_cards[i] judge_hand = [] for i in local_list.cards: judge_hand.append(i) score = score_hand(judge_hand) if score != "Not a Winning Hand": winning_hand = True else: winning_hand = False display_hand = [] for i in local_list.cards: display_hand.append(str(i)) url_hand = "" for i in game_hand.cards: url_hand += str(i) + "-" url_hand = url_hand[0:-1] print("Judge hand:\t", judge_hand) context = { 'cards': judge_hand, 'score': score, 'hold_cards': hold_cards_display, 'winning_hand': winning_hand, 'display_hand': display_hand, 'url_hand': url_hand } print(context) return render_template('game_result.html', **context)
class Player(object): def __init__(self, chips=100): self.chips = chips self.hand = Hand() def _subtract_chips(self, amt): if self.chips >= amt: self.chips -= amt else: raise StandardError("Not enough chips") def clear_hand(self): self.hand.clear() def bet(self, amt): self._subtract_chips(amt) def add_card(self, card): self.hand.add_card(card)
class House: def __init__(self): self.hand = Hand() def deal_card(self, card): self.hand.add_card(card) def showing_card(self): return self.hand.cards[0] def stay(self): if min(self.get_hand_values()) >= 17: return True return False def hit_hand(self, card): self.hand.hit(card) def get_hand_values(self): return self.hand.get_total_values()
def start_round(): global game_deck global game_hand global cards global card_list global ev_list global plays_context global ev_context game_deck = Deck() game_hand = Hand() for i in range(0, 5): game_hand.add_card(game_deck.draw_card()) print(game_hand) cards = str(game_hand).split(' ') cards.pop() #To prevent errors card_list = [Card(item) for item in cards] ev_list = analyze_hand(card_list) plays_context = [get_play_string(row[0]) for row in ev_list] ev_context = [row[1] for row in ev_list] return False
def play(p_opponent_value, p_deck_position, get_move): hand = Hand() card_values = hand.get_card_value() while True: hand.print_out_hand() move = get_move(card_values, p_opponent_value) if move == 2: return p_deck_position, 0, card_values if move == 1: card = deck[p_deck_position] p_deck_position += 1 hand.add_card(card) card_values = hand.get_card_value() if card_values > 21: hand.print_out_hand() return p_deck_position, -1, card_values if 21 > card_values > p_opponent_value: hand.print_out_hand() return p_deck_position, 1, card_values
def test_hand_count1(self): hand = Hand() hand.add_card(Card(11, 'Hearts')) hand.add_card(Card(6, 'Diamonds')) hand.add_card(Card(5, 'Spades')) total = hand.value() self.assertEqual(total, 21)
def test_hand_count3(self): hand = Hand() hand.add_card(Card(14, 'Hearts')) hand.add_card(Card(7, 'Clubs')) hand.add_card(Card(14, 'Diamonds')) total = hand.value() self.assertEqual(total, 19)
class Dealer(object): # Initializer def __init__(self): self.money = Money() self.hand = Hand() # Handles betting from the dealer's end def bet(self, bet_amt): if(self.money.bet_amt >= bet_amt): self.money.bet_amt = bet_amt self.money.remove(bet_amt) else: self.money = Money() self.money.bet_amt -= bet_amt # Handles gameplay from dealer's end. WILL ADD MORE HERE def play(self, game): while (self.hand.total < 17): self.hand.add_card(game.deck.draw_card()) # Prints dealer's hand total for player info def dealer_status(self): print("Dealer's hand total was : %d \n" % self.hand.total)
def new_game(): # создаем колоду d = Deck() # задаем "руки" для игрока и дилера player_hand = Hand("Player") dealer_hand = Hand("Dealer") # сдаем две карты игроку player_hand.add_card(d.deal_card()) player_hand.add_card(d.deal_card()) # сдаем одну карту дилеру dealer_hand.add_card(d.deal_card()) print(dealer_hand) print("=" * 20) print(player_hand) # Флаг проверки необходимости продолжать игру in_game = True # набирать карты игроку имеет смысл только если у него на руке меньше 21 очка while player_hand.get_value() < 21: ans = input("Hit or stand? (h/s) ") if ans == "h": player_hand.add_card(d.deal_card()) print(player_hand) # Если у игрока перебор - дилеру нет смысла набирать карты if player_hand.get_value() > 21: print("You lose") in_game = False else: print("You stand!") break print("=" * 20) if in_game: # По правилам дилер обязан набирать карты пока его счет меньше 17 while dealer_hand.get_value() < 17: dealer_hand.add_card(d.deal_card()) print(dealer_hand) # Если у дилера перебор играть дальше нет смысла - игрок выиграл if dealer_hand.get_value() > 21: print("Dealer bust") in_game = False if in_game: # Ни у кого не было перебора - сравниваем количество очков у игрока и дилера. # В нашей версии если у дилера и игрока равное количество очков - выигрывает казино if player_hand.get_value() > dealer_hand.get_value(): print("You win") else: print("Dealer win")
def test_point_options(): hand = Hand() hand.add_card(Card(3, 1)) assert hand.point_options == {3} hand.add_card(Card(1, 1)) assert hand.point_options == {4, 14} hand.add_card(Card(1, 1)) assert hand.point_options == {5, 15, 25}
def test_add_card(self): hand = Hand() card = Card() hand.add_card(card) cards_in_hand = hand.get_cards() self.assertEquals(len(cards_in_hand), 1)
class Dealer(object): def __init__(self): self.hand = Hand() def deal_card(self, card_table): card = card_table.shoe.get_next_card() for chair in card_table.chairs: chair.player.observe_card(card) return card def deal_round(self, card_table): for _ in range(2): for chair in card_table.chairs: if chair.hands[0]['bet'] is not "bankrupt": chair.hands[0]['hand'].add_card(self.deal_card(card_table)) else: chair.active = False for chair in card_table.chairs: if chair.active: self.hand.add_card(self.deal_card(card_table)) break def hit_dealer(self, card_table): while self.hand.is_soft(): if self.hand.total < 18: self.hand.add_card(self.deal_card(card_table)) else: break while self.hand.total < 17: self.hand.add_card(self.deal_card(card_table)) def pay_player(self, hand, chair): chair.player.bankroll += hand['bet'] * 2 def pay_player_blackjack(self, chair, blackjack_payout): bet = chair.hands[0]['bet'] + chair.hands[0]['bet'] * blackjack_payout chair.player.bankroll += bet def refund_player(self, hand, chair): chair.player.bankroll += hand['bet'] def resolve_round(self, card_table): for chair in card_table.chairs: if chair.active: self.hit_dealer(card_table) break for chair in card_table.chairs: if chair.active: if self.hand.is_busted(): for hand in chair.hands: if hand['hand'].is_busted() is False: self.pay_player(hand, chair) else: for hand in chair.hands: if self.hand.total < hand['hand'].total: self.pay_player(hand, chair) elif self.hand.total is hand['hand'].total: self.refund_player(hand, chair) def showing(self): return self.hand.cards[0].get_value()
class TestHand(unittest.TestCase): """ Tests the functionality of the Hand class. //TODO combine this with current functional tests, rewrite functional tests. """ def setUp(self): self.hand = Hand("Diamonds") def tearDown(self): self.hand = None def test_can_set_trump(self): """ Tests the ability to set the trump of a hand. """ self.assertEqual(self.hand.get_trump(), "Diamonds") def test_can_sort_normal_hand(self): """ Tests the ability to sort a hand that has no trumps or bowers. """ self.hand.add_card("T", "s") self.hand.add_card("Q", "s") self.hand.add_card("J", "s") self.hand.add_card("K", "s") self.hand.add_card("A", "s") self.hand.sort_hand() self.assertEqual(str(self.hand), "As\nKs\nQs\nJs\nTs") def test_can_sort_trump_hand(self): """ Tests the ability to sort a hand that has all trumps (and high bower). """ self.hand.add_card("T", "d") self.hand.add_card("Q", "d") self.hand.add_card("J", "d") self.hand.add_card("K", "d") self.hand.add_card("A", "d") self.hand.sort_hand() self.assertEqual(str(self.hand), "Jd\nAd\nKd\nQd\nTd") def test_can_sort_mixed_hand(self): """ Tests the ability to sort a hand that is mixed and includes both bowers. """ self.hand.add_card("T", "d") self.hand.add_card("Q", "c") self.hand.add_card("J", "h") self.hand.add_card("J", "d") self.hand.add_card("A", "d") self.hand.sort_hand() self.assertEqual(str(self.hand), "Jd\nJh\nAd\nTd\nQc")