-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tennis.py
More file actions
44 lines (34 loc) · 1.83 KB
/
test_tennis.py
File metadata and controls
44 lines (34 loc) · 1.83 KB
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
import unittest
from tennis import tennis_score
test_case_data = \
{ "even_scores" : [("Love-All", 0, 0),
("Fifteen-All", 1, 1),
("Thirty-All", 2, 2),
],
"early_games_with_uneven_scores" : [("Love-Fifteen", 0, 1),
("Fifteen-Love", 1, 0),
("Thirty-Fifteen", 2, 1),
("Forty-Thirty", 3, 2),
],
"endgame_with_uneven_scores": [("Advantage Player 1" 4, 3),
("Advantage Player 2" 5, 6),
("Advantage Player 1" 13, 12),
],
"there_is_a_winner": [("Win for Player 1", 4, 0),
("Win for Player 2", 2, 4),
("Win for Player 1", 6, 4),
],
}
def tennis_test_template(*args):
def foo(self):
self.assert_tennis_score(*args)
return foo
class TennisTest(unittest.TestCase):
def assert_tennis_score(self, expected_score, player1_points, player2_points):
self.assertEqual(expected_score, tennis_score(player1_points, player2_points))
for behaviour, test_cases in test_case_data.items():
for tennis_test_case_data in test_cases:
expected_output, player1_score, player2_score = tennis_test_case_data
test_name = "test_{0}_{1}_{2}".format(behaviour, player1_score, player2_score)
tennis_test_case = tennis_test_template(*tennis_test_case_data)
setattr(TennisTest, test_name, tennis_test_case)