From 1e8644c0d42879bbcf5baee22377bd8f68fa6772 Mon Sep 17 00:00:00 2001 From: spencer51324312 Date: Tue, 7 May 2019 21:47:54 -0400 Subject: [PATCH 1/9] update tournament tests Made it so it is more like the problem-specifications --- exercises/tournament/tournament_test.py | 136 ++++++++++++------------ 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/exercises/tournament/tournament_test.py b/exercises/tournament/tournament_test.py index fa3791db4bd..d9f19168a7a 100644 --- a/exercises/tournament/tournament_test.py +++ b/exercises/tournament/tournament_test.py @@ -8,107 +8,107 @@ class TournamentTest(unittest.TestCase): def test_just_the_header_if_no_input(self): self.assertEqual( - tally(''), - 'Team | MP | W | D | L | P' + tally([]), + ['Team | MP | W | D | L | P'] ) def test_a_win_is_three_points_and_a_loss_is_zero_points(self): - results = 'Allegoric Alaskans;Blithering Badgers;win' - table = ('Team | MP | W | D | L | P\n' - 'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n' - 'Blithering Badgers | 1 | 0 | 0 | 1 | 0') + results = ['Allegoric Alaskans;Blithering Badgers;win'] + table = ['Team | MP | W | D | L | P', + 'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3', + 'Blithering Badgers | 1 | 0 | 0 | 1 | 0'] self.assertEqual(tally(results), table) def test_a_win_can_also_be_expressed_as_a_loss(self): - results = 'Blithering Badgers;Allegoric Alaskans;loss' - table = ('Team | MP | W | D | L | P\n' - 'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n' - 'Blithering Badgers | 1 | 0 | 0 | 1 | 0') + results = ['Blithering Badgers;Allegoric Alaskans;loss'] + table = ['Team | MP | W | D | L | P', + 'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3', + 'Blithering Badgers | 1 | 0 | 0 | 1 | 0'] self.assertEqual(tally(results), table) def test_a_different_team_can_win(self): - results = 'Blithering Badgers;Allegoric Alaskans;win' - table = ('Team | MP | W | D | L | P\n' - 'Blithering Badgers | 1 | 1 | 0 | 0 | 3\n' - 'Allegoric Alaskans | 1 | 0 | 0 | 1 | 0') + results = ['Blithering Badgers;Allegoric Alaskans;win'] + table = ['Team | MP | W | D | L | P', + 'Blithering Badgers | 1 | 1 | 0 | 0 | 3', + 'Allegoric Alaskans | 1 | 0 | 0 | 1 | 0'] self.assertEqual(tally(results), table) def test_a_draw_is_one_point_each(self): - results = 'Allegoric Alaskans;Blithering Badgers;draw' - table = ('Team | MP | W | D | L | P\n' - 'Allegoric Alaskans | 1 | 0 | 1 | 0 | 1\n' - 'Blithering Badgers | 1 | 0 | 1 | 0 | 1') + results = ['Allegoric Alaskans;Blithering Badgers;draw'] + table = ['Team | MP | W | D | L | P', + 'Allegoric Alaskans | 1 | 0 | 1 | 0 | 1', + 'Blithering Badgers | 1 | 0 | 1 | 0 | 1'] self.assertEqual(tally(results), table) def test_there_can_be_more_than_one_match(self): - results = ('Allegoric Alaskans;Blithering Badgers;win\n' - 'Allegoric Alaskans;Blithering Badgers;win') - table = ('Team | MP | W | D | L | P\n' - 'Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n' - 'Blithering Badgers | 2 | 0 | 0 | 2 | 0') + results = ['Allegoric Alaskans;Blithering Badgers;win', + 'Allegoric Alaskans;Blithering Badgers;win'] + table = ['Team | MP | W | D | L | P', + 'Allegoric Alaskans | 2 | 2 | 0 | 0 | 6', + 'Blithering Badgers | 2 | 0 | 0 | 2 | 0'] self.assertEqual(tally(results), table) def test_there_can_be_more_than_one_winner(self): - results = ('Allegoric Alaskans;Blithering Badgers;loss\n' - 'Allegoric Alaskans;Blithering Badgers;win') - table = ('Team | MP | W | D | L | P\n' - 'Allegoric Alaskans | 2 | 1 | 0 | 1 | 3\n' - 'Blithering Badgers | 2 | 1 | 0 | 1 | 3') + results = ['Allegoric Alaskans;Blithering Badgers;loss', + 'Allegoric Alaskans;Blithering Badgers;win'] + table = ['Team | MP | W | D | L | P', + 'Allegoric Alaskans | 2 | 1 | 0 | 1 | 3', + 'Blithering Badgers | 2 | 1 | 0 | 1 | 3'] self.assertEqual(tally(results), table) def test_there_can_be_more_than_two_teams(self): - results = ('Allegoric Alaskans;Blithering Badgers;win\n' - 'Blithering Badgers;Courageous Californians;win\n' - 'Courageous Californians;Allegoric Alaskans;loss') - table = ('Team | MP | W | D | L | P\n' - 'Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n' - 'Blithering Badgers | 2 | 1 | 0 | 1 | 3\n' - 'Courageous Californians | 2 | 0 | 0 | 2 | 0') + results = ['Allegoric Alaskans;Blithering Badgers;win', + 'Blithering Badgers;Courageous Californians;win', + 'Courageous Californians;Allegoric Alaskans;loss'] + table = ['Team | MP | W | D | L | P', + 'Allegoric Alaskans | 2 | 2 | 0 | 0 | 6', + 'Blithering Badgers | 2 | 1 | 0 | 1 | 3', + 'Courageous Californians | 2 | 0 | 0 | 2 | 0'] self.assertEqual(tally(results), table) def test_typical_input(self): - results = ('Allegoric Alaskans;Blithering Badgers;win\n' - 'Devastating Donkeys;Courageous Californians;draw\n' - 'Devastating Donkeys;Allegoric Alaskans;win\n' - 'Courageous Californians;Blithering Badgers;loss\n' - 'Blithering Badgers;Devastating Donkeys;loss\n' - 'Allegoric Alaskans;Courageous Californians;win') - - table = ('Team | MP | W | D | L | P\n' - 'Devastating Donkeys | 3 | 2 | 1 | 0 | 7\n' - 'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n' - 'Blithering Badgers | 3 | 1 | 0 | 2 | 3\n' - 'Courageous Californians | 3 | 0 | 1 | 2 | 1') + results = ['Allegoric Alaskans;Blithering Badgers;win', + 'Devastating Donkeys;Courageous Californians;draw', + 'Devastating Donkeys;Allegoric Alaskans;win', + 'Courageous Californians;Blithering Badgers;loss', + 'Blithering Badgers;Devastating Donkeys;loss', + 'Allegoric Alaskans;Courageous Californians;win'] + + table = ['Team | MP | W | D | L | P', + 'Devastating Donkeys | 3 | 2 | 1 | 0 | 7', + 'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6', + 'Blithering Badgers | 3 | 1 | 0 | 2 | 3', + 'Courageous Californians | 3 | 0 | 1 | 2 | 1'] self.assertEqual(tally(results), table) def test_incomplete_competitionnot_not_all_pairs_have_played(self): - results = ('Allegoric Alaskans;Blithering Badgers;loss\n' - 'Devastating Donkeys;Allegoric Alaskans;loss\n' - 'Courageous Californians;Blithering Badgers;draw\n' - 'Allegoric Alaskans;Courageous Californians;win') + results = ['Allegoric Alaskans;Blithering Badgers;loss', + 'Devastating Donkeys;Allegoric Alaskans;loss', + 'Courageous Californians;Blithering Badgers;draw', + 'Allegoric Alaskans;Courageous Californians;win'] - table = ('Team | MP | W | D | L | P\n' - 'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n' - 'Blithering Badgers | 2 | 1 | 1 | 0 | 4\n' - 'Courageous Californians | 2 | 0 | 1 | 1 | 1\n' - 'Devastating Donkeys | 1 | 0 | 0 | 1 | 0') + table = ['Team | MP | W | D | L | P', + 'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6', + 'Blithering Badgers | 2 | 1 | 1 | 0 | 4', + 'Courageous Californians | 2 | 0 | 1 | 1 | 1', + 'Devastating Donkeys | 1 | 0 | 0 | 1 | 0'] self.assertEqual(tally(results), table) def test_ties_broken_alphabetically(self): - results = ('Courageous Californians;Devastating Donkeys;win\n' - 'Allegoric Alaskans;Blithering Badgers;win\n' - 'Devastating Donkeys;Allegoric Alaskans;loss\n' - 'Courageous Californians;Blithering Badgers;win\n' - 'Blithering Badgers;Devastating Donkeys;draw\n' - 'Allegoric Alaskans;Courageous Californians;draw') - - table = ('Team | MP | W | D | L | P\n' - 'Allegoric Alaskans | 3 | 2 | 1 | 0 | 7\n' - 'Courageous Californians | 3 | 2 | 1 | 0 | 7\n' - 'Blithering Badgers | 3 | 0 | 1 | 2 | 1\n' - 'Devastating Donkeys | 3 | 0 | 1 | 2 | 1') + results = ['Courageous Californians;Devastating Donkeys;win', + 'Allegoric Alaskans;Blithering Badgers;win', + 'Devastating Donkeys;Allegoric Alaskans;loss', + 'Courageous Californians;Blithering Badgers;win', + 'Blithering Badgers;Devastating Donkeys;draw', + 'Allegoric Alaskans;Courageous Californians;draw'] + + table = ['Team | MP | W | D | L | P', + 'Allegoric Alaskans | 3 | 2 | 1 | 0 | 7', + 'Courageous Californians | 3 | 2 | 1 | 0 | 7', + 'Blithering Badgers | 3 | 0 | 1 | 2 | 1', + 'Devastating Donkeys | 3 | 0 | 1 | 2 | 1'] self.assertEqual(tally(results), table) From 00ab1f397e323e64a01e6c87c42c0389795b6359 Mon Sep 17 00:00:00 2001 From: spencer51324312 Date: Tue, 7 May 2019 21:58:35 -0400 Subject: [PATCH 2/9] Update Example.py Changes tally function to accept the list instead of splitting the string --- exercises/tournament/example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/tournament/example.py b/exercises/tournament/example.py index e7b62874cd9..f25ac019bec 100644 --- a/exercises/tournament/example.py +++ b/exercises/tournament/example.py @@ -38,7 +38,7 @@ def format_table(results): def tally(data): table = defaultdict(lambda: [0, 0, 0]) - for line in data.split('\n'): + for line in data: for team, result in parse_game(line): table[team][result] += 1 From 92b23e2a4d251bf453062dfe4127b180c3132daa Mon Sep 17 00:00:00 2001 From: spencer51324312 Date: Tue, 7 May 2019 22:00:51 -0400 Subject: [PATCH 3/9] Updated the thign a --- exercises/tournament/example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/tournament/example.py b/exercises/tournament/example.py index f25ac019bec..c8d324aa998 100644 --- a/exercises/tournament/example.py +++ b/exercises/tournament/example.py @@ -37,7 +37,7 @@ def format_table(results): def tally(data): table = defaultdict(lambda: [0, 0, 0]) - + #now accepts non-string for line in data: for team, result in parse_game(line): table[team][result] += 1 From 562daa8c4d2e6431976974868dee7cac11b1aa3e Mon Sep 17 00:00:00 2001 From: spencer51324312 Date: Tue, 7 May 2019 22:07:09 -0400 Subject: [PATCH 4/9] Removed My Comment From File --- exercises/tournament/example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/tournament/example.py b/exercises/tournament/example.py index c8d324aa998..bc77aae86d4 100644 --- a/exercises/tournament/example.py +++ b/exercises/tournament/example.py @@ -37,7 +37,7 @@ def format_table(results): def tally(data): table = defaultdict(lambda: [0, 0, 0]) - #now accepts non-string + for line in data: for team, result in parse_game(line): table[team][result] += 1 From 4c7271f55fb7363ba3219cea9bf5c96f83c1a899 Mon Sep 17 00:00:00 2001 From: spencer51324312 Date: Tue, 7 May 2019 22:11:02 -0400 Subject: [PATCH 5/9] Removed My White Space --- exercises/tournament/example.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/tournament/example.py b/exercises/tournament/example.py index bc77aae86d4..dd6ed7c5f89 100644 --- a/exercises/tournament/example.py +++ b/exercises/tournament/example.py @@ -23,6 +23,7 @@ def calculate_points(stats): return stats[0] * 3 + stats[1] + def format_table(results): table = ['Team | MP | W | D | L | P'] @@ -37,7 +38,7 @@ def format_table(results): def tally(data): table = defaultdict(lambda: [0, 0, 0]) - + for line in data: for team, result in parse_game(line): table[team][result] += 1 From 9f7aa4603ca99b2c3212249489c750a60795ded3 Mon Sep 17 00:00:00 2001 From: spencer51324312 Date: Tue, 7 May 2019 22:12:35 -0400 Subject: [PATCH 6/9] Update example.py --- exercises/tournament/example.py | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/tournament/example.py b/exercises/tournament/example.py index dd6ed7c5f89..f25ac019bec 100644 --- a/exercises/tournament/example.py +++ b/exercises/tournament/example.py @@ -23,7 +23,6 @@ def calculate_points(stats): return stats[0] * 3 + stats[1] - def format_table(results): table = ['Team | MP | W | D | L | P'] From dbab68aeb659478fd4a5d64726253ad4bc4a731c Mon Sep 17 00:00:00 2001 From: spencer51324312 Date: Tue, 7 May 2019 22:30:34 -0400 Subject: [PATCH 7/9] Made it so tests now work as they should --- exercises/tournament/example.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exercises/tournament/example.py b/exercises/tournament/example.py index f25ac019bec..010f7441411 100644 --- a/exercises/tournament/example.py +++ b/exercises/tournament/example.py @@ -31,8 +31,8 @@ def format_table(results): team_fmt = '{0:30} | {1:2} | {3:2} | {4:2} | {5:2} | {2:2}' table.append( team_fmt.format(team, sum(games), calculate_points(games), *games)) + return table - return '\n'.join(table) def tally(data): @@ -40,6 +40,9 @@ def tally(data): for line in data: for team, result in parse_game(line): + print(team) + print(result) + print(table) table[team][result] += 1 return format_table(table) From 2dfb43126a95f59eafbc95f8eb45839dd8cba5af Mon Sep 17 00:00:00 2001 From: spencer51324312 Date: Tue, 7 May 2019 22:32:09 -0400 Subject: [PATCH 8/9] Update example.py --- exercises/tournament/example.py | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/tournament/example.py b/exercises/tournament/example.py index 010f7441411..6511ce70594 100644 --- a/exercises/tournament/example.py +++ b/exercises/tournament/example.py @@ -34,7 +34,6 @@ def format_table(results): return table - def tally(data): table = defaultdict(lambda: [0, 0, 0]) From 0bb524f8784560893769f4adb8c2e9f69de802bd Mon Sep 17 00:00:00 2001 From: spencer51324312 Date: Wed, 8 May 2019 10:51:12 -0400 Subject: [PATCH 9/9] Update example.py --- exercises/tournament/example.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/exercises/tournament/example.py b/exercises/tournament/example.py index 6511ce70594..88494049440 100644 --- a/exercises/tournament/example.py +++ b/exercises/tournament/example.py @@ -39,9 +39,6 @@ def tally(data): for line in data: for team, result in parse_game(line): - print(team) - print(result) - print(table) table[team][result] += 1 return format_table(table)