-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestBlackJack.py
executable file
·146 lines (129 loc) · 4.07 KB
/
TestBlackJack.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import unittest
import Model as M
class TestBlackJack(unittest.TestCase):
"""
Test script for blackjack model.
"""
def test_handInsert(self):
"""
Tests card hand insertion
:return:
"""
hand = M.Hand()
self.assertEqual(0, len(hand.hand))
hand.insert(M.Card(1, "h"))
self.assertEqual(1, len(hand.hand))
hand.insert(M.Card(1, "h"))
self.assertEqual(2, len(hand.hand))
def test_handDiscard(self):
"""
checks if discard empties hand properly
:return:
"""
hand = M.Hand()
hand.insert(M.Card(1, "h"))
hand.insert(M.Card(1, "h"))
hand.discard()
self.assertEqual(0, len(hand.hand))
def test_handTotal(self):
"""
tests different hand combinations to ensure
total function is counting card values correctly
:return:
"""
hand = M.Hand()
four = M.Card(4, "")
eight = M.Card(8, "")
ten = M.Card(10, "")
king = M.Card(13, "")
queen = M.Card(12, "")
jack = M.Card(11, "")
ace = M.Card(1, "")
# testing non-face cards
cardList = [four, eight, ten]
for card in cardList:
hand.insert(card)
self.assertEqual(22, hand.total())
hand.discard()
# testing if face card get correct value
cardList = [jack, queen, king]
for card in cardList:
hand.insert(card)
self.assertEqual(30, hand.total())
hand.discard()
# Testing if ace will be value 1
cardList = [ten, ace, eight]
for card in cardList:
hand.insert(card)
self.assertEqual(19, hand.total())
hand.discard()
# testing if ace will be value 11
cardList = [ten, ace]
for card in cardList:
hand.insert(card)
self.assertEqual(21, hand.total())
hand.discard()
def test_CardValue(self):
"""
Checking if card have appropriate values.
:return:
"""
self.assertEqual(5, M.Card(5, "").value)
self.assertEqual(10, M.Card(12, "").value)
self.assertEqual(11, M.Card(1, "").value)
def test_DeckFormation(self):
"""
Ensures that deck that is created has proper number of cards.
:return:
"""
deck = M.Deck()
self.assertEqual(52, len(deck.deck))
def test_DeckDeal(self):
"""
ensures that deck is losing cards as it deals
:return:
"""
deck = M.Deck()
deck.dealCard()
self.assertEqual(51, len(deck.deck))
def test_PlayerGetCard(self):
"""
Ensuring that player can get cards from deck.
:return:
"""
player = M.Player("test")
deck = M.Deck()
self.assertEqual(0, len(player.hand.hand))
player.getCard(deck)
self.assertEqual(1, len(player.hand.hand))
def test_findWinner(self):
"""
Makes sure that appropriate player is winning
:return:
"""
player = M.Player("test")
dealer = M.Dealer()
deck = M.Deck()
player.getCard(deck)
player.getCard(deck)
dealer.getCard(deck)
dealer.getCard(deck)
self.assertEqual("Dylan Fossl", M.findWinner(player, dealer))
player.getCard(deck)
self.assertEqual(player, M.findWinner(player, dealer))
dealer.getCard(deck)
dealer.getCard(deck)
self.assertEqual(dealer, M.findWinner(player, dealer))
def test_DealerHitDecision(self):
"""
makes sure dealer is hitting when they should be.
:return:
"""
dealer = M.Dealer()
deck = M.Deck()
dealer.getCard(deck)
self.assertEqual(True, dealer.hitDecision())
dealer.getCard(deck)
self.assertEqual(False, dealer.hitDecision())
if __name__ == '__main__':
unittest.main()