|
8 | 8 | class TournamentTest(unittest.TestCase): |
9 | 9 | def test_just_the_header_if_no_input(self): |
10 | 10 | self.assertEqual( |
11 | | - tally(''), |
12 | | - 'Team | MP | W | D | L | P' |
| 11 | + tally([]), |
| 12 | + ['Team | MP | W | D | L | P'] |
13 | 13 | ) |
14 | 14 |
|
15 | 15 | 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'] |
20 | 20 | self.assertEqual(tally(results), table) |
21 | 21 |
|
22 | 22 | 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'] |
27 | 27 | self.assertEqual(tally(results), table) |
28 | 28 |
|
29 | 29 | 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'] |
34 | 34 | self.assertEqual(tally(results), table) |
35 | 35 |
|
36 | 36 | 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'] |
41 | 41 | self.assertEqual(tally(results), table) |
42 | 42 |
|
43 | 43 | 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'] |
49 | 49 | self.assertEqual(tally(results), table) |
50 | 50 |
|
51 | 51 | 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'] |
57 | 57 | self.assertEqual(tally(results), table) |
58 | 58 |
|
59 | 59 | 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'] |
67 | 67 | self.assertEqual(tally(results), table) |
68 | 68 |
|
69 | 69 | 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'] |
82 | 82 |
|
83 | 83 | self.assertEqual(tally(results), table) |
84 | 84 |
|
85 | 85 | 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'] |
90 | 90 |
|
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'] |
96 | 96 |
|
97 | 97 | self.assertEqual(tally(results), table) |
98 | 98 |
|
99 | 99 | 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'] |
112 | 112 |
|
113 | 113 | self.assertEqual(tally(results), table) |
114 | 114 |
|
|
0 commit comments