|
2 | 2 |
|
3 | 3 | from tournament import tally |
4 | 4 |
|
5 | | - |
6 | 5 | # Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0 |
7 | 6 |
|
| 7 | + |
8 | 8 | class TournamentTest(unittest.TestCase): |
9 | 9 | def test_just_the_header_if_no_input(self): |
10 | | - self.assertEqual( |
11 | | - tally([]), |
12 | | - ['Team | MP | W | D | L | P'] |
13 | | - ) |
| 10 | + results = [] |
| 11 | + table = ["Team | MP | W | D | L | P"] |
| 12 | + self.assertEqual(tally(results), table) |
14 | 13 |
|
15 | 14 | def test_a_win_is_three_points_a_loss_is_zero_points(self): |
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'] |
| 15 | + results = ["Allegoric Alaskans;Blithering Badgers;win"] |
| 16 | + table = [ |
| 17 | + "Team | MP | W | D | L | P", |
| 18 | + "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3", |
| 19 | + "Blithering Badgers | 1 | 0 | 0 | 1 | 0", |
| 20 | + ] |
20 | 21 | self.assertEqual(tally(results), table) |
21 | 22 |
|
22 | 23 | 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', |
25 | | - 'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3', |
26 | | - 'Blithering Badgers | 1 | 0 | 0 | 1 | 0'] |
| 24 | + results = ["Blithering Badgers;Allegoric Alaskans;loss"] |
| 25 | + table = [ |
| 26 | + "Team | MP | W | D | L | P", |
| 27 | + "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3", |
| 28 | + "Blithering Badgers | 1 | 0 | 0 | 1 | 0", |
| 29 | + ] |
27 | 30 | self.assertEqual(tally(results), table) |
28 | 31 |
|
29 | 32 | def test_a_different_team_can_win(self): |
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'] |
| 33 | + results = ["Blithering Badgers;Allegoric Alaskans;win"] |
| 34 | + table = [ |
| 35 | + "Team | MP | W | D | L | P", |
| 36 | + "Blithering Badgers | 1 | 1 | 0 | 0 | 3", |
| 37 | + "Allegoric Alaskans | 1 | 0 | 0 | 1 | 0", |
| 38 | + ] |
34 | 39 | self.assertEqual(tally(results), table) |
35 | 40 |
|
36 | 41 | def test_a_draw_is_one_point_each(self): |
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'] |
| 42 | + results = ["Allegoric Alaskans;Blithering Badgers;draw"] |
| 43 | + table = [ |
| 44 | + "Team | MP | W | D | L | P", |
| 45 | + "Allegoric Alaskans | 1 | 0 | 1 | 0 | 1", |
| 46 | + "Blithering Badgers | 1 | 0 | 1 | 0 | 1", |
| 47 | + ] |
41 | 48 | self.assertEqual(tally(results), table) |
42 | 49 |
|
43 | 50 | def test_there_can_be_more_than_one_match(self): |
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'] |
| 51 | + results = [ |
| 52 | + "Allegoric Alaskans;Blithering Badgers;win", |
| 53 | + "Allegoric Alaskans;Blithering Badgers;win", |
| 54 | + ] |
| 55 | + table = [ |
| 56 | + "Team | MP | W | D | L | P", |
| 57 | + "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6", |
| 58 | + "Blithering Badgers | 2 | 0 | 0 | 2 | 0", |
| 59 | + ] |
49 | 60 | self.assertEqual(tally(results), table) |
50 | 61 |
|
51 | 62 | def test_there_can_be_more_than_one_winner(self): |
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'] |
| 63 | + results = [ |
| 64 | + "Allegoric Alaskans;Blithering Badgers;loss", |
| 65 | + "Allegoric Alaskans;Blithering Badgers;win", |
| 66 | + ] |
| 67 | + table = [ |
| 68 | + "Team | MP | W | D | L | P", |
| 69 | + "Allegoric Alaskans | 2 | 1 | 0 | 1 | 3", |
| 70 | + "Blithering Badgers | 2 | 1 | 0 | 1 | 3", |
| 71 | + ] |
57 | 72 | self.assertEqual(tally(results), table) |
58 | 73 |
|
59 | 74 | def test_there_can_be_more_than_two_teams(self): |
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'] |
| 75 | + results = [ |
| 76 | + "Allegoric Alaskans;Blithering Badgers;win", |
| 77 | + "Blithering Badgers;Courageous Californians;win", |
| 78 | + "Courageous Californians;Allegoric Alaskans;loss", |
| 79 | + ] |
| 80 | + table = [ |
| 81 | + "Team | MP | W | D | L | P", |
| 82 | + "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6", |
| 83 | + "Blithering Badgers | 2 | 1 | 0 | 1 | 3", |
| 84 | + "Courageous Californians | 2 | 0 | 0 | 2 | 0", |
| 85 | + ] |
67 | 86 | self.assertEqual(tally(results), table) |
68 | 87 |
|
69 | 88 | def test_typical_input(self): |
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 | | - |
| 89 | + results = [ |
| 90 | + "Allegoric Alaskans;Blithering Badgers;win", |
| 91 | + "Devastating Donkeys;Courageous Californians;draw", |
| 92 | + "Devastating Donkeys;Allegoric Alaskans;win", |
| 93 | + "Courageous Californians;Blithering Badgers;loss", |
| 94 | + "Blithering Badgers;Devastating Donkeys;loss", |
| 95 | + "Allegoric Alaskans;Courageous Californians;win", |
| 96 | + ] |
| 97 | + table = [ |
| 98 | + "Team | MP | W | D | L | P", |
| 99 | + "Devastating Donkeys | 3 | 2 | 1 | 0 | 7", |
| 100 | + "Allegoric Alaskans | 3 | 2 | 0 | 1 | 6", |
| 101 | + "Blithering Badgers | 3 | 1 | 0 | 2 | 3", |
| 102 | + "Courageous Californians | 3 | 0 | 1 | 2 | 1", |
| 103 | + ] |
83 | 104 | self.assertEqual(tally(results), table) |
84 | 105 |
|
85 | 106 | def test_incomplete_competition_not_all_pairs_have_played(self): |
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 | | - |
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 | | - |
| 107 | + results = [ |
| 108 | + "Allegoric Alaskans;Blithering Badgers;loss", |
| 109 | + "Devastating Donkeys;Allegoric Alaskans;loss", |
| 110 | + "Courageous Californians;Blithering Badgers;draw", |
| 111 | + "Allegoric Alaskans;Courageous Californians;win", |
| 112 | + ] |
| 113 | + table = [ |
| 114 | + "Team | MP | W | D | L | P", |
| 115 | + "Allegoric Alaskans | 3 | 2 | 0 | 1 | 6", |
| 116 | + "Blithering Badgers | 2 | 1 | 1 | 0 | 4", |
| 117 | + "Courageous Californians | 2 | 0 | 1 | 1 | 1", |
| 118 | + "Devastating Donkeys | 1 | 0 | 0 | 1 | 0", |
| 119 | + ] |
97 | 120 | self.assertEqual(tally(results), table) |
98 | 121 |
|
99 | 122 | def test_ties_broken_alphabetically(self): |
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 | | - |
| 123 | + results = [ |
| 124 | + "Courageous Californians;Devastating Donkeys;win", |
| 125 | + "Allegoric Alaskans;Blithering Badgers;win", |
| 126 | + "Devastating Donkeys;Allegoric Alaskans;loss", |
| 127 | + "Courageous Californians;Blithering Badgers;win", |
| 128 | + "Blithering Badgers;Devastating Donkeys;draw", |
| 129 | + "Allegoric Alaskans;Courageous Californians;draw", |
| 130 | + ] |
| 131 | + table = [ |
| 132 | + "Team | MP | W | D | L | P", |
| 133 | + "Allegoric Alaskans | 3 | 2 | 1 | 0 | 7", |
| 134 | + "Courageous Californians | 3 | 2 | 1 | 0 | 7", |
| 135 | + "Blithering Badgers | 3 | 0 | 1 | 2 | 1", |
| 136 | + "Devastating Donkeys | 3 | 0 | 1 | 2 | 1", |
| 137 | + ] |
113 | 138 | self.assertEqual(tally(results), table) |
114 | 139 |
|
115 | 140 |
|
116 | | -if __name__ == '__main__': |
| 141 | +if __name__ == "__main__": |
117 | 142 | unittest.main() |
0 commit comments