-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_print_results.py
159 lines (119 loc) · 5.47 KB
/
test_print_results.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
147
148
149
150
151
152
153
154
155
156
157
158
159
from unittest import TestCase
from unittest.mock import patch, MagicMock
from blackjack import print_game_results
from player import Player
from card import Card
# noinspection PyUnusedLocal
@patch('blackjack.print')
class TestPrintResults(TestCase):
def test_print_results__one_person__is_winner(self, mock_print: MagicMock):
person = Player("Matthew")
person.print_player = MagicMock()
person.cards = []
print_game_results([person])
mock_print.assert_called_once_with("Winner: Matthew")
def test_print_results__one_person_empty_hand(self, mock_print: MagicMock):
person = Player("Matthew")
person.print_player = MagicMock()
print_game_results([person])
person.print_player.assert_called_once()
def test_print_results__one_person_low_hand(self, mock_print: MagicMock):
person = Player("Matthew")
person.print_player = MagicMock()
person.cards = [Card(2, "Test")]
print_game_results([person])
person.print_player.assert_called_once()
def test_print_results__one_person_high_hand(self, mock_print: MagicMock):
person = Player("Matthew")
person.print_player = MagicMock()
person.cards = [Card(10, "Test"), Card(10, "Test"), Card(10, "Test")]
print_game_results([person])
person.print_player.assert_called_once()
def test_print_results__people_print_person_called_once(self, mock_print: MagicMock):
matt = Player("Matthew")
matt.print_player = MagicMock()
matt.cards = [Card(2, "Test")]
sam = Player("Sam")
sam.print_player = MagicMock()
sam.cards = [Card(10, "Test")]
hannah = Player("Hannah")
hannah.print_player = MagicMock()
hannah.cards = [Card(5, "Test")]
players = [matt, sam, hannah]
print_game_results(players)
for player in players:
with self.subTest(player=player.name):
# noinspection PyUnresolvedReferences
player.print_player.assert_called_once()
def test_print_results__people_single_winner(self, mock_print: MagicMock):
matt = Player("Matthew")
matt.print_player = MagicMock()
matt.cards = [Card(2, "Test")]
sam = Player("Sam")
sam.print_player = MagicMock()
sam.cards = [Card(10, "Test")]
hannah = Player("Hannah")
hannah.print_player = MagicMock()
hannah.cards = [Card(5, "Test")]
players = [matt, sam, hannah]
print_game_results(players)
mock_print.assert_called_once_with("Winner: Sam")
def test_print_results__people_joint_winner(self, mock_print: MagicMock):
matt = Player("Matthew")
matt.print_player = MagicMock()
matt.cards = [Card(2, "Test")]
sam = Player("Sam")
sam.print_player = MagicMock()
sam.cards = [Card(10, "Test")]
hannah = Player("Hannah")
hannah.print_player = MagicMock()
hannah.cards = [Card(10, "Test")]
players = [matt, sam, hannah]
print_game_results(players)
mock_print.assert_any_call("Winner: Sam")
mock_print.assert_any_call("Winner: Hannah")
self.assertRaises(AssertionError, lambda: mock_print.assert_any_call("Winner: Matthew"))
def test_print_results__people_single_winner_one_over(self, mock_print: MagicMock):
matt = Player("Matthew")
matt.print_player = MagicMock()
matt.cards = [Card(10, "Test"), Card(10, "Test"), Card(10, "Test")]
sam = Player("Sam")
sam.print_player = MagicMock()
sam.cards = [Card(10, "Test")]
hannah = Player("Hannah")
hannah.print_player = MagicMock()
hannah.cards = [Card(5, "Test")]
players = [matt, sam, hannah]
print_game_results(players)
mock_print.assert_called_once_with("Winner: Sam")
def test_print_results__people_joint_winner_one_over(self, mock_print: MagicMock):
matt = Player("Matthew")
matt.print_player = MagicMock()
matt.cards = [Card(10, "Test"), Card(10, "Test"), Card(10, "Test")]
sam = Player("Sam")
sam.print_player = MagicMock()
sam.cards = [Card(10, "Test")]
hannah = Player("Hannah")
hannah.print_player = MagicMock()
hannah.cards = [Card(10, "Test")]
players = [matt, sam, hannah]
print_game_results(players)
mock_print.assert_any_call("Winner: Sam")
mock_print.assert_any_call("Winner: Hannah")
self.assertRaises(AssertionError, lambda: mock_print.assert_any_call("Winner: Matthew"))
def test_print_results__people_no_winner(self, mock_print: MagicMock):
matt = Player("Matthew")
matt.print_player = MagicMock()
matt.cards = [Card(10, "Test"), Card(10, "Test"), Card(10, "Test")]
sam = Player("Sam")
sam.print_player = MagicMock()
sam.cards = [Card(10, "Test"), Card(10, "Test"), Card(10, "Test")]
hannah = Player("Hannah")
hannah.print_player = MagicMock()
hannah.cards = [Card(10, "Test"), Card(10, "Test"), Card(10, "Test")]
players = [matt, sam, hannah]
print_game_results(players)
self.assertRaises(AssertionError, lambda: mock_print.assert_any_call("Winner: Matthew"))
self.assertRaises(AssertionError, lambda: mock_print.assert_any_call("Winner: Sam"))
self.assertRaises(AssertionError, lambda: mock_print.assert_any_call("Winner: Hannah"))
mock_print.assert_called_once_with("No winner")