populate each hand with two cards. Take a card from the deck
and put it in the player_hand list. Then, take a card from the deck and
put it in the dealer_hand list. Do that one more time in that order so that the dealer and player have each two cards. Make sure the dealer’s first card is face down. I keep receiving this error from my 2 tests.
My code:
while len(dealer_hand) != 2 and len(player_hand) != 2:
player_card = random.choice(deck)
player_hand.append(player_card)
deck.remove(player_card)
if len(player_hand) == 2:
player_hand[0].face_up()
player_hand[1].face_up()
dealer_card = random.choice(deck)
dealer_hand.append(dealer_card)
deck.remove(dealer_card)
if len(dealer_hand) == 2:
dealer_hand[0].face_down()
dealer_hand[1].face_up()
return player_hand and dealer_hand
False != True
Expected :True
Actual :False
def test_deal_cards():
deck = []
for suit in cards.SUITS:
for rank in cards.RANKS:
deck.append(cards.Card(suit, rank))
dealer_hand = []
player_hand = []
blackjack.deal_cards(deck, dealer_hand, player_hand)
assert len(dealer_hand) == 2
assert len(player_hand) == 2
> assert dealer_hand[0].is_face_up() is True
E assert False is True
E + where False = <bound method Card.is_face_up of [10 of Hearts]>()
E + where <bound method Card.is_face_up of [10 of Hearts]> = [10 of Hearts].is_face_up
test_deal_cards.py:19: AssertionError
(test_deal_cards_alternates_between_player_and_dealer)
[7 of Hearts] != [6 of Spades]
Expected :[6 of Spades]
Actual :[7 of Hearts]
def test_deal_cards_alternates_between_player_and_dealer():
card1 = cards.Card(cards.SPADES, cards.SIX)
card2 = cards.Card(cards.HEARTS, cards.SEVEN)
card3 = cards.Card(cards.CLUBS, cards.EIGHT)
card4 = cards.Card(cards.DIAMONDS, cards.NINE)
deck = [card4, card3, card2, card1]
dealer_hand = []
player_hand = []
blackjack.deal_cards(deck, dealer_hand, player_hand)
assert len(dealer_hand) == 2
assert len(player_hand) == 2
> assert player_hand[0] is card1, 'Player 1st card should be Six of Spades'
E AssertionError: Player 1st card should be Six of Spades
E assert [7 of Hearts] is [6 of Spades]
test_deal_cards.py:39: AssertionError
>Solution :
I think the error lies within the first line:
while len(dealer_hand) and len(player_hand) != 2:
If you want to check if the dealer also has 2 cards, you need to fix that line to:
while len(dealer_hand) != 2 and len(player_hand) != 2: