-
Notifications
You must be signed in to change notification settings - Fork 0
/
tennis_game_tests.py
151 lines (135 loc) · 4.92 KB
/
tennis_game_tests.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
import unittest
from tennis_game import TennisGame, Player
class TestTennisGame(unittest.TestCase):
def test_returns_fifteen_love_when_score_1_0(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(1),
Player().called("Roger").with_points(0)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("fifteen-love", actual_score)
def test_returns_fifteen_all_when_score_1_1(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(1),
Player().called("Roger").with_points(1)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("fifteen-all", actual_score)
def test_returns_love_fifteen_when_score_0_1(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(0),
Player().called("Roger").with_points(1)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("love-fifteen", actual_score)
def test_returns_thirty_fifteen_when_score_2_1(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(2),
Player().called("Roger").with_points(1)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("thirty-fifteen", actual_score)
def test_returns_thirty_forty_when_score_2_3(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(2),
Player().called("Roger").with_points(3)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("thirty-forty", actual_score)
def test_returns_deuce_when_score_3_3(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(3),
Player().called("Roger").with_points(3)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("deuce", actual_score)
def test_returns_advantage_player1_when_score_4_3(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(4),
Player().called("Roger").with_points(3)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("advantage Rafael", actual_score)
def test_returns_advantage_player2_when_score_3_4(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(3),
Player().called("Roger").with_points(4)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("advantage Roger", actual_score)
def test_returns_advantage_player1_when_score_5_4(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(5),
Player().called("Roger").with_points(4)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("advantage Rafael", actual_score)
def test_returns_advantage_player2_when_score_5_6(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(5),
Player().called("Roger").with_points(6)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("advantage Roger", actual_score)
def test_returns_player1_wins_when_score_4_2(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(4),
Player().called("Roger").with_points(2)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("Rafael wins", actual_score)
def test_returns_player2_wins_when_score_9_11(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(9),
Player().called("Roger").with_points(11)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("Roger wins", actual_score)
def test_returns_deuce_score_score_16_16(self):
# arrange
tennis_game = TennisGame().with_players(
Player().called("Rafael").with_points(16),
Player().called("Roger").with_points(16)
)
# act
actual_score = tennis_game.score
# assert
self.assertEqual("deuce", actual_score)
if __name__ == '__main__':
unittest.main()