33from tournament import tally
44
55
6- # test cases adapted from `x-common//canonical-data.json` @ version: 1.1 .0
6+ # test cases adapted from `x-common//canonical-data.json` @ version: 1.3 .0
77
88class TestTournament (unittest .TestCase ):
9+ def test_just_the_header_if_no_input (self ):
10+ self .assertEqual (
11+ tally ('' ),
12+ 'Team | MP | W | D | L | P'
13+ )
14+
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' )
20+ self .assertEqual (tally (results ), table )
21+
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' )
27+ self .assertEqual (tally (results ), table )
28+
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' )
34+ self .assertEqual (tally (results ), table )
35+
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' )
41+ self .assertEqual (tally (results ), table )
42+
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' )
49+ self .assertEqual (tally (results ), table )
50+
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' )
57+ self .assertEqual (tally (results ), table )
58+
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' )
67+ self .assertEqual (tally (results ), table )
68+
969 def test_typical_input (self ):
1070 results = ('Allegoric Alaskans;Blithering Badgers;win\n '
1171 'Devastating Donkeys;Courageous Californians;draw\n '
@@ -22,7 +82,7 @@ def test_typical_input(self):
2282
2383 self .assertEqual (tally (results ), table )
2484
25- def test_incomplete_competitionnot_all_pairs_have_played (self ):
85+ def test_incomplete_competitionnot_not_all_pairs_have_played (self ):
2686 results = ('Allegoric Alaskans;Blithering Badgers;loss\n '
2787 'Devastating Donkeys;Allegoric Alaskans;loss\n '
2888 'Courageous Californians;Blithering Badgers;draw\n '
@@ -52,19 +112,6 @@ def test_ties_broken_alphabetically(self):
52112
53113 self .assertEqual (tally (results ), table )
54114
55- def test_mostly_invalid_lines (self ):
56- results = ('\n '
57- 'Allegoric Alaskans@Blithering Badgers;draw\n '
58- 'Blithering Badgers;Devastating Donkeys;loss\n '
59- 'Devastating Donkeys;Courageous Californians;win;5\n '
60- 'Courageous Californians;Allegoric Alaskans;los' )
61-
62- table = ('Team | MP | W | D | L | P\n '
63- 'Devastating Donkeys | 1 | 1 | 0 | 0 | 3\n '
64- 'Blithering Badgers | 1 | 0 | 0 | 1 | 0' )
65-
66- self .assertEqual (tally (results ), table )
67-
68115
69116if __name__ == '__main__' :
70117 unittest .main ()
0 commit comments