From b43cf5c565f79ff65b1fb682b5a53a88d54a6154 Mon Sep 17 00:00:00 2001 From: bijal Date: Sat, 11 Jun 2016 07:02:09 +1000 Subject: [PATCH 1/3] Introduced testReportMatches() that runs 3-rounds with 8 players --- vagrant/tournament/tournament_test.py | 88 ++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/vagrant/tournament/tournament_test.py b/vagrant/tournament/tournament_test.py index 1272dd6dff..d19b71b543 100644 --- a/vagrant/tournament/tournament_test.py +++ b/vagrant/tournament/tournament_test.py @@ -68,6 +68,7 @@ def testStandingsBeforeMatches(): "even if they have no matches played.") print "6. Newly registered players appear in the standings with no matches." + def testReportMatches(): """ Test that matches are reported properly. @@ -101,7 +102,89 @@ def testReportMatches(): raise ValueError("After deleting matches, players should have zero matches recorded.") if w != 0: raise ValueError("After deleting matches, players should have zero wins recorded.") - print "8. After match deletion, player standings are properly reset.\n9. Matches are properly deleted." + print "8. After match deletion, player standings are properly reset." + print "9. Matches are properly deleted." + + +def testReportMatches_8players(): + """ + Test that matches are reported properly. + Test to confirm matches are deleted properly. + """ + deleteMatches() + deletePlayers() + registerPlayer("Bruno Walton") + registerPlayer("Boots O'Neal") + registerPlayer("Cathy Burton") + registerPlayer("Diane Grant") + registerPlayer("Clark Wayne") + registerPlayer("Bruce Parker") + registerPlayer("Peter Kent") + registerPlayer("Dr. Yu") + standings = playerStandings() + [id1, id2, id3, id4, id5, id6, id7, id8] = [row[0] for row in standings] + reportMatch(id1, id2) + reportMatch(id3, id4) + reportMatch(id5, id6) + reportMatch(id7, id8) + standings = playerStandings() + if len(standings) != 8: + raise ValueError("Standings of all eight players not reported.") + for (i, n, w, m) in standings: + if m != 1: + raise ValueError("Each player should have one match recorded.") + if i in (id1, id3, id5, id7) and w != 1: + raise ValueError("Each match winner should have one win recorded.") + elif i in (id2, id4, id6, id8) and w != 0: + raise ValueError("Each match loser should have zero wins recorded.") + print "10. After round-one of eight-player tournament, players have updated standings." + reportMatch(id3, id1) + reportMatch(id7, id5) + reportMatch(id4, id2) + reportMatch(id6, id8) + standings = playerStandings() + if len(standings) != 8: + raise ValueError("Standings of all eight players not reported.") + for (i, n, w, m) in standings: + if m != 2: + raise ValueError("Each player should have two matches recorded after the second round") + if i in (id3, id7) and w != 2: + raise ValueError("Match winner(s) with two wins not recorded") + if i in (id1, id5, id4, id6) and w != 1: + raise ValueError("Player(s) with one win not recorded.") + if i in (id2, id8) and w != 0: + raise ValueError("Player(s) with zero wins not recorded.") + print "11. After round-two of eight-player tournament, players have updated standings." + reportMatch(id7, id3) + reportMatch(id5, id1) + reportMatch(id4, id6) + reportMatch(id8, id2) + standings = playerStandings() + if len(standings) != 8: + raise ValueError("Standings of all eight players not reported.") + for (i, n, w, m) in standings: + if m != 3: + raise ValueError("Each player should have three matches recorded after the third round") + if i==id7 and w != 3: + raise ValueError("Match winner(s) with three wins not recorded") + if i in (id3, id4, id5) and w != 2: + raise ValueError("Match winner(s) with two wins not recorded") + if i in (id1, id6, id8) and w != 1: + raise ValueError("Player(s) with one win not recorded.") + if i==id2 and w != 0: + raise ValueError("Player(s) with zero wins not recorded.") + print "12. After round-three of eight-player tournament, players have updated standings." + deleteMatches() + standings = playerStandings() + if len(standings) != 8: + raise ValueError("Match deletion should not change number of players in standings.") + for (i, n, w, m) in standings: + if m != 0: + raise ValueError("After deleting matches, players should have zero matches recorded.") + if w != 0: + raise ValueError("After deleting matches, players should have zero wins recorded.") + print "13. After match deletion, player standings are properly reset." + print "14. Matches are properly deleted." def testPairings(): """ @@ -144,12 +227,13 @@ def testPairings(): if pair not in possible_pairs: raise ValueError( "After one match, players with one win should be paired.") - print "10. After one match, players with one win are properly paired." + print "15. After one match, players with one win are properly paired." if __name__ == '__main__': testCount() testStandingsBeforeMatches() testReportMatches() + testReportMatches_8players() testPairings() print "Success! All tests pass!" From 953edf5075b4cc2cdf5640d34f4821549e7ff587 Mon Sep 17 00:00:00 2001 From: bijal Date: Sun, 12 Jun 2016 03:16:45 +1000 Subject: [PATCH 2/3] Introduced testPairings_8players_3rounds() to test pairing for all 3 rounds --- vagrant/tournament/tournament_test.py | 94 +++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/vagrant/tournament/tournament_test.py b/vagrant/tournament/tournament_test.py index d19b71b543..e5f859a384 100644 --- a/vagrant/tournament/tournament_test.py +++ b/vagrant/tournament/tournament_test.py @@ -123,6 +123,8 @@ def testReportMatches_8players(): registerPlayer("Dr. Yu") standings = playerStandings() [id1, id2, id3, id4, id5, id6, id7, id8] = [row[0] for row in standings] + + # Round #1 reportMatch(id1, id2) reportMatch(id3, id4) reportMatch(id5, id6) @@ -138,6 +140,8 @@ def testReportMatches_8players(): elif i in (id2, id4, id6, id8) and w != 0: raise ValueError("Each match loser should have zero wins recorded.") print "10. After round-one of eight-player tournament, players have updated standings." + + # Round #2 reportMatch(id3, id1) reportMatch(id7, id5) reportMatch(id4, id2) @@ -155,6 +159,8 @@ def testReportMatches_8players(): if i in (id2, id8) and w != 0: raise ValueError("Player(s) with zero wins not recorded.") print "11. After round-two of eight-player tournament, players have updated standings." + + # Round #3 reportMatch(id7, id3) reportMatch(id5, id1) reportMatch(id4, id6) @@ -230,10 +236,98 @@ def testPairings(): print "15. After one match, players with one win are properly paired." +def testPairings_8players_3rounds(): + """ + Test that pairings are generated properly both before and after match reporting. + """ + deleteMatches() + deletePlayers() + registerPlayer("Twilight Sparkle") + registerPlayer("Fluttershy") + registerPlayer("Applejack") + registerPlayer("Pinkie Pie") + registerPlayer("Rarity") + registerPlayer("Rainbow Dash") + registerPlayer("Princess Celestia") + registerPlayer("Princess Luna") + standings = playerStandings() + [id1, id2, id3, id4, id5, id6, id7, id8] = [row[0] for row in standings] + pairings = swissPairings() + if len(pairings) != 4: + raise ValueError( + "For eight players, swissPairings should return 4 pairs. Got {pairs}".format(pairs=len(pairings))) + # playerStandings() has been tested in testReportMatches_8players() for 3 rounds, + # use those results to test pairings + standings = playerStandings() + # Turn the result into lookup dictionary of this kind => {playerid: Number_of_victories} + player_victories = dict([ (standing[0],standing[2]) for standing in standings]) + for pair in pairings: + player_a_victories = player_victories[pair[0]] + player_b_victories = player_victories[pair[2]] + if player_a_victories != player_b_victories: + raise ValueError("These two players round#1 are paired incorrectly for round #2"\ + "{id_a}(victories=player_a_victories) and "\ + "{id_b}(victories=player_b_victories)".format(\ + id_a=pair[0], player_a_victories=player_a_victories, + id_b=pair[2], player_b_victories=player_b_victories)) + print "16. All players paired correctly for round#1" + + # Run Round #1 + reportMatch(id1, id2) + reportMatch(id3, id4) + reportMatch(id5, id6) + reportMatch(id7, id8) + pairings = swissPairings() + if len(pairings) != 4: + raise ValueError( + "For eight players, swissPairings should return 4 pairs. Got {pairs}".format(pairs=len(pairings))) + # playerStandings() has been tested in testReportMatches_8players() for 3 rounds, + # use those results to test pairings + standings = playerStandings() + # Turn the result into lookup dictionary of this kind => {playerid: Number_of_victories} + player_victories = dict([ (standing[0],standing[2]) for standing in standings]) + for pair in pairings: + player_a_victories = player_victories[pair[0]] + player_b_victories = player_victories[pair[2]] + if player_a_victories != player_b_victories: + raise ValueError("These two players for round#2 (after round#1) are paired incorrectly "\ + "{id_a}(victories=player_a_victories) and "\ + "{id_b}(victories=player_b_victories)".format(\ + id_a=pair[0], player_a_victories=player_a_victories, + id_b=pair[2], player_b_victories=player_b_victories)) + print "17. All players paired correctly for round #2 (after round#1)" + + # Run Round #2 + reportMatch(id3, id1) + reportMatch(id7, id5) + reportMatch(id4, id2) + reportMatch(id6, id8) + pairings = swissPairings() + if len(pairings) != 4: + raise ValueError( + "For eight players, swissPairings should return 4 pairs. Got {pairs}".format(pairs=len(pairings))) + # playerStandings() has been tested in testReportMatches_8players() for 3 rounds, + # use those results to test pairings + standings = playerStandings() + # Turn the result into lookup dictionary of this kind => {playerid: Number_of_victories} + player_victories = dict([ (standing[0],standing[2]) for standing in standings]) + for pair in pairings: + player_a_victories = player_victories[pair[0]] + player_b_victories = player_victories[pair[2]] + if player_a_victories != player_b_victories: + raise ValueError("These two players for round #3 (after round#2) are paired incorrectly "\ + "{id_a}(victories=player_a_victories) and "\ + "{id_b}(victories=player_b_victories)".format(\ + id_a=pair[0], player_a_victories=player_a_victories, + id_b=pair[2], player_b_victories=player_b_victories)) + print "18. All players paired correctly for round #3 (after round#2)" + + if __name__ == '__main__': testCount() testStandingsBeforeMatches() testReportMatches() testReportMatches_8players() testPairings() + testPairings_8players_3rounds() print "Success! All tests pass!" From fc7847c13a7606f5fc2da8b8dff5abf4f8cdf44b Mon Sep 17 00:00:00 2001 From: bijal Date: Sun, 12 Jun 2016 03:40:02 +1000 Subject: [PATCH 3/3] Bug displaying correct victories count fixed in testPairings_8players_3rounds() --- vagrant/tournament/tournament_test.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vagrant/tournament/tournament_test.py b/vagrant/tournament/tournament_test.py index e5f859a384..ea70d5a0cf 100644 --- a/vagrant/tournament/tournament_test.py +++ b/vagrant/tournament/tournament_test.py @@ -266,8 +266,8 @@ def testPairings_8players_3rounds(): player_b_victories = player_victories[pair[2]] if player_a_victories != player_b_victories: raise ValueError("These two players round#1 are paired incorrectly for round #2"\ - "{id_a}(victories=player_a_victories) and "\ - "{id_b}(victories=player_b_victories)".format(\ + "{id_a}(victories={player_a_victories}) and "\ + "{id_b}(victories={player_b_victories})".format(\ id_a=pair[0], player_a_victories=player_a_victories, id_b=pair[2], player_b_victories=player_b_victories)) print "16. All players paired correctly for round#1" @@ -291,8 +291,8 @@ def testPairings_8players_3rounds(): player_b_victories = player_victories[pair[2]] if player_a_victories != player_b_victories: raise ValueError("These two players for round#2 (after round#1) are paired incorrectly "\ - "{id_a}(victories=player_a_victories) and "\ - "{id_b}(victories=player_b_victories)".format(\ + "{id_a}(victories={player_a_victories}) and "\ + "{id_b}(victories={player_b_victories})".format(\ id_a=pair[0], player_a_victories=player_a_victories, id_b=pair[2], player_b_victories=player_b_victories)) print "17. All players paired correctly for round #2 (after round#1)" @@ -316,8 +316,8 @@ def testPairings_8players_3rounds(): player_b_victories = player_victories[pair[2]] if player_a_victories != player_b_victories: raise ValueError("These two players for round #3 (after round#2) are paired incorrectly "\ - "{id_a}(victories=player_a_victories) and "\ - "{id_b}(victories=player_b_victories)".format(\ + "{id_a}(victories={player_a_victories}) and "\ + "{id_b}(victories={player_b_victories})".format(\ id_a=pair[0], player_a_victories=player_a_victories, id_b=pair[2], player_b_victories=player_b_victories)) print "18. All players paired correctly for round #3 (after round#2)"