-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_blackjack.py
74 lines (54 loc) · 1.97 KB
/
test_blackjack.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import unittest
import blackjack
class TestBlackJackCard(unittest.TestCase):
def test_str(self):
text = 'Two of Hearts'
result = str(blackjack.Card('Hearts', 'Two'))
self.assertEqual(result, text)
def test_value(self):
value = 4
card = blackjack.Card('Diamonds', 'Four')
self.assertEqual(card.value, value)
class TestBlackJackDeck(unittest.TestCase):
def test_init(self):
self.assertEqual(len(blackjack.Deck()), 52)
def test_shuffle(self):
test_deck = blackjack.Deck()
self.assertIsNone(test_deck.shuffle())
def test_deal(self):
test_deck = blackjack.Deck()
result = str(test_deck.deal())
text = 'Ace of Clubs'
self.assertEqual(result, text)
class TestBlackJackHand(unittest.TestCase):
def test_add_card(self):
test_hand = blackjack.Hand()
test_hand.cards = ['Two of Hearts', 'Ace of Spades']
test_hand.add_card('King of Clubs')
result = ['Two of Hearts', 'Ace of Spades', 'King of Clubs']
self.assertEqual(result.sort(), test_hand.cards.sort())
def test_check_ace(self):
test_hand = blackjack.Hand()
test_hand.cards = ['Ace of Hearts', 'Ace of Spades']
test_hand.check_for_ace()
self.assertEqual(2, test_hand.aces)
def test_adjust_ace(self):
test_hand = blackjack.Hand()
test_hand.value = 31
test_hand.adjust_for_ace()
self.assertEqual(21, test_hand.value)
class TestBlackJackChips(unittest.TestCase):
def test_win_bet(self):
test_chips = blackjack.Chips()
test_chips.total = 100
test_chips.bet = 20
test_chips.win_bet()
self.assertEqual(120, test_chips.total)
def test_lose_bet(self):
test_chips = blackjack.Chips()
test_chips.total = 100
test_chips.bet = 30
test_chips.lose_bet()
self.assertEqual(70, test_chips.total)
if __name__ == '__main__':
unittest.main()