-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_rps.py
67 lines (54 loc) · 1.77 KB
/
test_rps.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
import unittest
from unittest.mock import patch, MagicMock
from rps import RPS, GameObject, AIPlayer, Hand
class RpsTest(unittest.TestCase):
def setUp(self):
self.rps = RPS()
self.choices = self.rps.choices
self.rock = self.choices[Hand.R]
self.paper = self.choices[Hand.P]
self.scissors = self.choices[Hand.S]
def test_winner(self):
'''test the outcomes of each of the game object choices'''
testCases = [
(self.rock, self.paper, 'LOSE'),
(self.rock, self.scissors, 'WIN'),
(self.rock, self.rock, 'DRAW'),
(self.paper, self.paper, 'DRAW'),
(self.paper, self.scissors, 'LOSE'),
(self.paper, self.rock, 'WIN'),
(self.scissors, self.paper, 'WIN'),
(self.scissors, self.scissors, 'DRAW'),
(self.scissors, self.rock, 'LOSE'),
]
for player_1, player_2, outcome in testCases:
actual = player_1.winner(player_2)
self.assertEqual(actual.value, outcome)
def test_input_args(self):
testCases = [
('1', Hand.R),
('2', Hand.P),
('3', Hand.S),
('0', None),
('A', None),
('r', 'R'),
('s', 'S'),
('q', 'Q'),
('c', 'C'),
(1, None),
(2, None),
(3, None),
]
for user_input, expected in testCases:
actual = self.rps.get_turn(user_input)
self.assertEqual(actual, expected)
@patch("rps.user_input")
def test_run(self, input_m):
cases = [
'1', 's', 'Q'
]
input_m.side_effect = cases
# run game
self.rps.run()
if __name__ == '__main__':
unittest.main()