-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_blackjack.py
122 lines (96 loc) · 3.66 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
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
"""test_blackjack.py -- test suite for blackjack.py"""
import unittest
from blackjack import Card, Deck, Player, Round, Dealer
class TestCard(unittest.TestCase):
"""test the card"""
def setUp(self):
"""set up instance of card to test functionality"""
self.card = Card('Ace', 'Spades', 1)
def tearDown(self):
pass
def test_get_name(self):
"""test getter function"""
self.assertEqual(self.card.name, 'Ace')
def test_set_name(self):
"""test setter function"""
self.card.set_name('King')
self.assertEqual(self.card.name, 'King')
def test_get_suit(self):
"""test getter function"""
self.assertEqual(self.card.suit, 'Spades')
def test_set_suit(self):
"""test setter function"""
self.card.set_suit('Hearts')
self.assertEqual(self.card.suit, 'Hearts')
def test_get_value(self):
"""test getter function"""
self.assertEqual(self.card.value, 1)
def test_set_value(self):
"""test setter function"""
self.card.set_value(2)
self.assertEqual(self.card.value, 2)
class TestDeck(unittest.TestCase):
"""test deck class"""
def setUp(self):
"""set up to test deck"""
self.test_deck = Deck()
def test___len__(self):
self.assertEqual(len(self.test_deck), 52)
def test_shuffle(self):
self.assertEqual(self.test_deck.shuffle(), None)
def test_take_top_card(self):
self.assertIsInstance(self.test_deck.take_top_card(), Card)
class TestPlayer(unittest.TestCase):
"""test the instance of player"""
def setUp(self):
self.player = Player('player1')
self.card = Card('Ace', 'Diamonds', 1)
def test_add_card_to_hand(self):
"""test whether you add a hand"""
self.player.add_card_to_hand(self.card)
self.assertEqual(self.player.hand[0], self.card)
def test_set_hand(self):
"""test set hand method"""
with self.assertRaises(ValueError):
self.player.set_hand(1)
self.player.set_hand(tuple(1))
self.player.set_hand(bool)
def test_check_if_busted(self):
"""tests if busted works correctly"""
self.assertFalse(self.player.check_if_busted())
self.player.set_score(21)
self.assertFalse(self.player.check_if_busted())
self.player.set_score(22)
self.assertTrue(self.player.check_if_busted())
def test_set_is_in_game(self):
"""test setter method for the is_in_game attribute"""
with self.assertRaises(ValueError):
self.player.set_is_in_game(list)
self.player.set_is_in_game('string')
self.player.set_is_in_game(bool)
result = self.player.set_is_in_game(True)
self.assertEqual(result, True)
def test_update_score(self):
"""test update_score method"""
card1 = Card("Ace", "Hearts", 1)
card2 = Card("Ace", "Hearts", 1)
card3 = Card("Ace", "Hearts", 1)
self.player.set_hand([card1, card2, card3])
self.assertEqual(self.player.update_score(), 3)
class TestRound(unittest.TestCase):
"""test round class"""
def setUp(self):
self.round = Round()
def test___init___(self):
"""test init function"""
self.assertIsInstance(self.round.deck, Deck)
self.assertIsInstance(self.round.dealer, Dealer)
def test_deal_cards(self):
"""make sure each step is working appropriately"""
# 1. shuffle deck
self.assertNotEqual(self.round.deck, Deck().deck)
# TODO: finish test case
def test_hit_players(self):
"""test for players"""
# TODO: finish test case
pass