-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hand.py
More file actions
99 lines (82 loc) · 3.36 KB
/
test_hand.py
File metadata and controls
99 lines (82 loc) · 3.36 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from unittest import TestCase
from blackjack import Hand, Card
class TestHand(TestCase):
def setUp(self):
self.hand = Hand()
def tearDown(self):
self.hand.cards.clear()
def test_hit(self):
card = Card('2', 'clubs')
self.assertEqual(0, len(self.hand.cards))
self.hand.hit(card)
self.assertEqual(1, len(self.hand.cards))
self.assertTrue(card in self.hand.cards)
def test_value(self):
self.hand.cards.extend([Card('A', 'spade'), Card('A', 'heart')])
self.assertEqual(12, self.hand.value())
self.hand.cards.append(Card('2', 'club'))
self.assertEqual(14, self.hand.value())
self.hand.cards.append(Card('K', 'diamond'))
self.assertEqual(14, self.hand.value())
self.hand.cards.append(Card('Q', 'heart'))
self.assertEqual(24, self.hand.value())
def test_value_blackjack(self):
self.hand.cards.extend([Card('A', 'spade'), Card('J', 'spade')])
self.assertEqual(21, self.hand.value())
def test_settle_bust(self):
self.hand.cards.append(Card('K', 'hearts'))
self.hand.cards.append(Card('K', 'diamonds'))
self.hand.cards.append(Card('K', 'clubs'))
self.hand.bet = 10
other = Hand()
other.cards.append(Card('Q', 'hearts'))
other.cards.append(Card('Q', 'diamonds'))
actual = self.hand.settle(other)
self.assertEqual('bust', self.hand.state)
self.assertEqual(0, self.hand.bet)
self.assertEqual(10, actual)
def test_settle_other_bust(self):
self.hand.cards.append(Card('K', 'hearts'))
self.hand.cards.append(Card('K', 'diamonds'))
self.hand.bet = 10
other = Hand()
other.cards.append(Card('Q', 'hearts'))
other.cards.append(Card('Q', 'diamonds'))
other.cards.append(Card('Q', 'clubs'))
actual = self.hand.settle(other)
self.assertEqual('win', self.hand.state)
self.assertEqual(20, self.hand.bet)
self.assertEqual(-10, actual)
def test_settle_push(self):
self.hand.cards.append(Card('K', 'hearts'))
self.hand.cards.append(Card('K', 'diamonds'))
self.hand.bet = 10
other = Hand()
other.cards.append(Card('Q', 'hearts'))
other.cards.append(Card('Q', 'diamonds'))
actual = self.hand.settle(other)
self.assertEqual('push', self.hand.state)
self.assertEqual(10, self.hand.bet)
self.assertEqual(0, actual)
def test_settle_other_win(self):
self.hand.cards.append(Card('K', 'hearts'))
self.hand.cards.append(Card('9', 'diamonds'))
self.hand.bet = 10
other = Hand()
other.cards.append(Card('Q', 'hearts'))
other.cards.append(Card('Q', 'diamonds'))
actual = self.hand.settle(other)
self.assertEqual('lose', self.hand.state)
self.assertEqual(0, self.hand.bet)
self.assertEqual(10, actual)
def test_settle_win(self):
self.hand.cards.append(Card('K', 'hearts'))
self.hand.cards.append(Card('K', 'diamonds'))
self.hand.bet = 10
other = Hand()
other.cards.append(Card('Q', 'hearts'))
other.cards.append(Card('9', 'diamonds'))
actual = self.hand.settle(other)
self.assertEqual('win', self.hand.state)
self.assertEqual(20, self.hand.bet)
self.assertEqual(-10, actual)