-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjokenpo.py
47 lines (30 loc) · 1.61 KB
/
jokenpo.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
import unittest
def enum(**enums):
return type('Enum', (), enums)
Jokenpo = enum(ROCK=3, PAPER=1, SCISSORS=2)
def judge(play1, play2):
if play1 == play2:
return 'draw'
PAPER_WINS_ROCK = not (play1 + play2) % 2
return Jokenpo.PAPER if PAPER_WINS_ROCK else max(play1, play2)
class JokenpoTests(unittest.TestCase):
def test_Player1_is_Rock_and_Player2_is_Rock_Must_be_Draw(self):
self.assertEqual(judge(Jokenpo.ROCK, Jokenpo.ROCK), "draw")
def test_Player1_is_Paper_and_Player2_is_Paper_Must_be_Draw(self):
self.assertEqual(judge(Jokenpo.PAPER, Jokenpo.PAPER), "draw")
def test_Player1_is_Scissors_and_Player2_is_Scissors_Must_be_Draw(self):
self.assertEqual(judge(Jokenpo.SCISSORS, Jokenpo.SCISSORS), "draw")
def test_Player1_is_Rock_and_Player2_is_Scissors_Must_be_Rock(self):
self.assertEqual(judge(Jokenpo.ROCK, Jokenpo.SCISSORS), Jokenpo.ROCK)
def test_Player1_is_Scissors_and_Player2_is_Paper_Must_be_Scissors(self):
self.assertEqual(judge(Jokenpo.SCISSORS, Jokenpo.PAPER), Jokenpo.SCISSORS)
def test_Player1_is_Paper_and_Player2_is_Rock_Must_be_Paper(self):
self.assertEqual(judge(Jokenpo.PAPER, Jokenpo.ROCK), Jokenpo.PAPER)
def test_Player2_is_Rock_and_Player1_is_Scissors_Must_be_Rock(self):
self.assertEqual(judge(Jokenpo.SCISSORS, Jokenpo.ROCK), Jokenpo.ROCK)
def test_Player2_is_Scissors_and_Player1_is_Paper_Must_be_Scissors(self):
self.assertEqual(judge(Jokenpo.PAPER, Jokenpo.SCISSORS), Jokenpo.SCISSORS)
def test_Player2_is_Paper_and_Player1_is_Rock_Must_be_Paper(self):
self.assertEqual(judge(Jokenpo.ROCK, Jokenpo.PAPER), Jokenpo.PAPER)
if __name__ == '__main__':
unittest.main()