Skip to content

Commit 8a23959

Browse files
spencer51324312cmccandless
authored andcommitted
Changed tournament_tests files (exercism#1776)
* update tournament tests Made it so it is more like the problem-specifications
1 parent 09920dd commit 8a23959

2 files changed

Lines changed: 70 additions & 71 deletions

File tree

exercises/tournament/example.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@ def format_table(results):
3131
team_fmt = '{0:30} | {1:2} | {3:2} | {4:2} | {5:2} | {2:2}'
3232
table.append(
3333
team_fmt.format(team, sum(games), calculate_points(games), *games))
34-
35-
return '\n'.join(table)
34+
return table
3635

3736

3837
def tally(data):
3938
table = defaultdict(lambda: [0, 0, 0])
4039

41-
for line in data.split('\n'):
40+
for line in data:
4241
for team, result in parse_game(line):
4342
table[team][result] += 1
4443

exercises/tournament/tournament_test.py

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,107 +8,107 @@
88
class TournamentTest(unittest.TestCase):
99
def test_just_the_header_if_no_input(self):
1010
self.assertEqual(
11-
tally(''),
12-
'Team | MP | W | D | L | P'
11+
tally([]),
12+
['Team | MP | W | D | L | P']
1313
)
1414

1515
def test_a_win_is_three_points_and_a_loss_is_zero_points(self):
16-
results = 'Allegoric Alaskans;Blithering Badgers;win'
17-
table = ('Team | MP | W | D | L | P\n'
18-
'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n'
19-
'Blithering Badgers | 1 | 0 | 0 | 1 | 0')
16+
results = ['Allegoric Alaskans;Blithering Badgers;win']
17+
table = ['Team | MP | W | D | L | P',
18+
'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3',
19+
'Blithering Badgers | 1 | 0 | 0 | 1 | 0']
2020
self.assertEqual(tally(results), table)
2121

2222
def test_a_win_can_also_be_expressed_as_a_loss(self):
23-
results = 'Blithering Badgers;Allegoric Alaskans;loss'
24-
table = ('Team | MP | W | D | L | P\n'
25-
'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n'
26-
'Blithering Badgers | 1 | 0 | 0 | 1 | 0')
23+
results = ['Blithering Badgers;Allegoric Alaskans;loss']
24+
table = ['Team | MP | W | D | L | P',
25+
'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3',
26+
'Blithering Badgers | 1 | 0 | 0 | 1 | 0']
2727
self.assertEqual(tally(results), table)
2828

2929
def test_a_different_team_can_win(self):
30-
results = 'Blithering Badgers;Allegoric Alaskans;win'
31-
table = ('Team | MP | W | D | L | P\n'
32-
'Blithering Badgers | 1 | 1 | 0 | 0 | 3\n'
33-
'Allegoric Alaskans | 1 | 0 | 0 | 1 | 0')
30+
results = ['Blithering Badgers;Allegoric Alaskans;win']
31+
table = ['Team | MP | W | D | L | P',
32+
'Blithering Badgers | 1 | 1 | 0 | 0 | 3',
33+
'Allegoric Alaskans | 1 | 0 | 0 | 1 | 0']
3434
self.assertEqual(tally(results), table)
3535

3636
def test_a_draw_is_one_point_each(self):
37-
results = 'Allegoric Alaskans;Blithering Badgers;draw'
38-
table = ('Team | MP | W | D | L | P\n'
39-
'Allegoric Alaskans | 1 | 0 | 1 | 0 | 1\n'
40-
'Blithering Badgers | 1 | 0 | 1 | 0 | 1')
37+
results = ['Allegoric Alaskans;Blithering Badgers;draw']
38+
table = ['Team | MP | W | D | L | P',
39+
'Allegoric Alaskans | 1 | 0 | 1 | 0 | 1',
40+
'Blithering Badgers | 1 | 0 | 1 | 0 | 1']
4141
self.assertEqual(tally(results), table)
4242

4343
def test_there_can_be_more_than_one_match(self):
44-
results = ('Allegoric Alaskans;Blithering Badgers;win\n'
45-
'Allegoric Alaskans;Blithering Badgers;win')
46-
table = ('Team | MP | W | D | L | P\n'
47-
'Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n'
48-
'Blithering Badgers | 2 | 0 | 0 | 2 | 0')
44+
results = ['Allegoric Alaskans;Blithering Badgers;win',
45+
'Allegoric Alaskans;Blithering Badgers;win']
46+
table = ['Team | MP | W | D | L | P',
47+
'Allegoric Alaskans | 2 | 2 | 0 | 0 | 6',
48+
'Blithering Badgers | 2 | 0 | 0 | 2 | 0']
4949
self.assertEqual(tally(results), table)
5050

5151
def test_there_can_be_more_than_one_winner(self):
52-
results = ('Allegoric Alaskans;Blithering Badgers;loss\n'
53-
'Allegoric Alaskans;Blithering Badgers;win')
54-
table = ('Team | MP | W | D | L | P\n'
55-
'Allegoric Alaskans | 2 | 1 | 0 | 1 | 3\n'
56-
'Blithering Badgers | 2 | 1 | 0 | 1 | 3')
52+
results = ['Allegoric Alaskans;Blithering Badgers;loss',
53+
'Allegoric Alaskans;Blithering Badgers;win']
54+
table = ['Team | MP | W | D | L | P',
55+
'Allegoric Alaskans | 2 | 1 | 0 | 1 | 3',
56+
'Blithering Badgers | 2 | 1 | 0 | 1 | 3']
5757
self.assertEqual(tally(results), table)
5858

5959
def test_there_can_be_more_than_two_teams(self):
60-
results = ('Allegoric Alaskans;Blithering Badgers;win\n'
61-
'Blithering Badgers;Courageous Californians;win\n'
62-
'Courageous Californians;Allegoric Alaskans;loss')
63-
table = ('Team | MP | W | D | L | P\n'
64-
'Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n'
65-
'Blithering Badgers | 2 | 1 | 0 | 1 | 3\n'
66-
'Courageous Californians | 2 | 0 | 0 | 2 | 0')
60+
results = ['Allegoric Alaskans;Blithering Badgers;win',
61+
'Blithering Badgers;Courageous Californians;win',
62+
'Courageous Californians;Allegoric Alaskans;loss']
63+
table = ['Team | MP | W | D | L | P',
64+
'Allegoric Alaskans | 2 | 2 | 0 | 0 | 6',
65+
'Blithering Badgers | 2 | 1 | 0 | 1 | 3',
66+
'Courageous Californians | 2 | 0 | 0 | 2 | 0']
6767
self.assertEqual(tally(results), table)
6868

6969
def test_typical_input(self):
70-
results = ('Allegoric Alaskans;Blithering Badgers;win\n'
71-
'Devastating Donkeys;Courageous Californians;draw\n'
72-
'Devastating Donkeys;Allegoric Alaskans;win\n'
73-
'Courageous Californians;Blithering Badgers;loss\n'
74-
'Blithering Badgers;Devastating Donkeys;loss\n'
75-
'Allegoric Alaskans;Courageous Californians;win')
76-
77-
table = ('Team | MP | W | D | L | P\n'
78-
'Devastating Donkeys | 3 | 2 | 1 | 0 | 7\n'
79-
'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n'
80-
'Blithering Badgers | 3 | 1 | 0 | 2 | 3\n'
81-
'Courageous Californians | 3 | 0 | 1 | 2 | 1')
70+
results = ['Allegoric Alaskans;Blithering Badgers;win',
71+
'Devastating Donkeys;Courageous Californians;draw',
72+
'Devastating Donkeys;Allegoric Alaskans;win',
73+
'Courageous Californians;Blithering Badgers;loss',
74+
'Blithering Badgers;Devastating Donkeys;loss',
75+
'Allegoric Alaskans;Courageous Californians;win']
76+
77+
table = ['Team | MP | W | D | L | P',
78+
'Devastating Donkeys | 3 | 2 | 1 | 0 | 7',
79+
'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6',
80+
'Blithering Badgers | 3 | 1 | 0 | 2 | 3',
81+
'Courageous Californians | 3 | 0 | 1 | 2 | 1']
8282

8383
self.assertEqual(tally(results), table)
8484

8585
def test_incomplete_competitionnot_not_all_pairs_have_played(self):
86-
results = ('Allegoric Alaskans;Blithering Badgers;loss\n'
87-
'Devastating Donkeys;Allegoric Alaskans;loss\n'
88-
'Courageous Californians;Blithering Badgers;draw\n'
89-
'Allegoric Alaskans;Courageous Californians;win')
86+
results = ['Allegoric Alaskans;Blithering Badgers;loss',
87+
'Devastating Donkeys;Allegoric Alaskans;loss',
88+
'Courageous Californians;Blithering Badgers;draw',
89+
'Allegoric Alaskans;Courageous Californians;win']
9090

91-
table = ('Team | MP | W | D | L | P\n'
92-
'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n'
93-
'Blithering Badgers | 2 | 1 | 1 | 0 | 4\n'
94-
'Courageous Californians | 2 | 0 | 1 | 1 | 1\n'
95-
'Devastating Donkeys | 1 | 0 | 0 | 1 | 0')
91+
table = ['Team | MP | W | D | L | P',
92+
'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6',
93+
'Blithering Badgers | 2 | 1 | 1 | 0 | 4',
94+
'Courageous Californians | 2 | 0 | 1 | 1 | 1',
95+
'Devastating Donkeys | 1 | 0 | 0 | 1 | 0']
9696

9797
self.assertEqual(tally(results), table)
9898

9999
def test_ties_broken_alphabetically(self):
100-
results = ('Courageous Californians;Devastating Donkeys;win\n'
101-
'Allegoric Alaskans;Blithering Badgers;win\n'
102-
'Devastating Donkeys;Allegoric Alaskans;loss\n'
103-
'Courageous Californians;Blithering Badgers;win\n'
104-
'Blithering Badgers;Devastating Donkeys;draw\n'
105-
'Allegoric Alaskans;Courageous Californians;draw')
106-
107-
table = ('Team | MP | W | D | L | P\n'
108-
'Allegoric Alaskans | 3 | 2 | 1 | 0 | 7\n'
109-
'Courageous Californians | 3 | 2 | 1 | 0 | 7\n'
110-
'Blithering Badgers | 3 | 0 | 1 | 2 | 1\n'
111-
'Devastating Donkeys | 3 | 0 | 1 | 2 | 1')
100+
results = ['Courageous Californians;Devastating Donkeys;win',
101+
'Allegoric Alaskans;Blithering Badgers;win',
102+
'Devastating Donkeys;Allegoric Alaskans;loss',
103+
'Courageous Californians;Blithering Badgers;win',
104+
'Blithering Badgers;Devastating Donkeys;draw',
105+
'Allegoric Alaskans;Courageous Californians;draw']
106+
107+
table = ['Team | MP | W | D | L | P',
108+
'Allegoric Alaskans | 3 | 2 | 1 | 0 | 7',
109+
'Courageous Californians | 3 | 2 | 1 | 0 | 7',
110+
'Blithering Badgers | 3 | 0 | 1 | 2 | 1',
111+
'Devastating Donkeys | 3 | 0 | 1 | 2 | 1']
112112

113113
self.assertEqual(tally(results), table)
114114

0 commit comments

Comments
 (0)