-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_blackjackgame.py
51 lines (43 loc) · 1.72 KB
/
test_blackjackgame.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from blackjack_game import BlackjackGame
def test_card_values_notzero_after_assignment():
"""tests whether each card gets value assigned"""
samplegame = BlackjackGame()
samplegame.assign_card_values()
for card in samplegame.deck.cards:
assert card.value != 0
def test_card_values_total_after_assignment():
"""test whether total deck value is correct"""
samplegame = BlackjackGame()
samplegame.assign_card_values()
total = 0
for card in samplegame.deck.cards:
total += card.value
assert total == (40 * 3 + sum(range(1, 11)) * 4)
def test_dealerhandvalue_2aces():
"""test whether the hand value is counted correctly when 2 aces on hand"""
samplegame = BlackjackGame()
samplegame.assign_card_values()
indexes = []
for _ in range(2):
for card in samplegame.deck.cards:
if card.rank == "Ace":
indexes.append(samplegame.deck.cards.index(card))
break
for index in indexes:
samplegame.dealer.hand.append(samplegame.deck.cards[index])
samplegame.calculate_handvalue(samplegame.dealer)
assert samplegame.dealer.handvalue == 21
def test_dealerhandvalue_2kings():
"""test whether the hand value is counted correctly when 2 kings on hand"""
samplegame = BlackjackGame()
samplegame.assign_card_values()
indexes = []
for _ in range(2):
for card in samplegame.deck.cards:
if card.rank == "King":
indexes.append(samplegame.deck.cards.index(card))
break
for index in indexes:
samplegame.dealer.hand.append(samplegame.deck.cards[index])
samplegame.calculate_handvalue(samplegame.dealer)
assert samplegame.dealer.handvalue == 20