Exemple #1
0
    def test_report_matches(self):
        """Test reporting matches."""
        tournament_id = tournament.register_tournament(
            "Test Matches Tournament", 4)
        player_names = ("Bruno Walton", "Boots O'Neal", "Cathy Burton",
                        "Diane Grant")
        for player_name in player_names:
            tournament.register_player_in_tournament(
                tournament.register_player(player_name), tournament_id)

        standings = tournament.player_standings_by_tournament(tournament_id)
        player1, player2, player3, player4 = [row[0] for row in standings]
        tournament.report_match(player1, player2, tournament_id)
        tournament.report_match(player3, player4, tournament_id)

        standings = tournament.player_standings()
        for id, name, wins, matches in standings:
            # Each player should have one match recorded
            self.assertEqual(matches, 1)
            # Each match winner should have one win recorded
            if id in (player1, player3):
                self.assertEqual(wins, 1)
            # Each match loser should have zero wins recorded
            elif id in (player2, player4):
                self.assertEqual(wins, 0)
        print "* After a match, players have updated standings."
Exemple #2
0
    def test_standings_before_matches(self):
        """Test players standings before matches."""
        tournament.register_player("Melpomene Murray")
        tournament.register_player("Randy Schwartz")
        standings = tournament.player_standings()

        # Players should appear in player_standings before playing in matches
        # Only registered players should appear in standings
        self.assertEqual(len(standings), 2)

        # Each player_standings row should have four columns
        self.assertEqual(len(standings[0]), 4)

        # Newly registered players should have no matches or wins
        [(id1, name1, wins1, match1), (id2, name2, wins2, match2)] = standings
        for standing in (match1, match2, wins1, wins2):
            self.assertEqual(standing, 0)

        # Registered players' names should appear in standings even when
        # no matches have been played.
        self.assertEqual(set([name1, name2]),
                         set(["Melpomene Murray", "Randy Schwartz"]))
        print(
            "* Newly registered players appear in the "
            "standings with no matches.")
    def test_standings_before_matches(self):
        """Test to ensure players are properly represented in standings.

        Standings are analysed prior to any matches being reported.
        """
        self._register_players(["Melpomene Murray", "Randy Schwartz"])
        standings = player_standings()
        self._assert_standings_length(standings)
        self._assert_standings_values(standings)
        msg = "6. Newly registered players appear"
        print msg + " in the standings with no matches."
 def _assert_standings_values_after_first_round(self, id1, id2, id3, id4):
     standings = player_standings()
     for (i, n, w, m) in standings:
         self.assertEqual(
             m, 1, "Each player should have one match recorded.")
         if i in (id1, id3):
             self.assertTrue(
                 w == 1, "Each match winner should have one win recorded.")
         if i in (id2, id4):
             self.assertTrue(
                 w == 0, "Each match loser should have zero wins recorded.")
 def _assert_standings_values_after_first_round(self, id1, id2, id3, id4):
     standings = player_standings()
     for (i, n, w, m) in standings:
         self.assertEqual(m, 1,
                          "Each player should have one match recorded.")
         if i in (id1, id3):
             self.assertTrue(
                 w == 1, "Each match winner should have one win recorded.")
         if i in (id2, id4):
             self.assertTrue(
                 w == 0, "Each match loser should have zero wins recorded.")
    def test_standings_before_matches(self):
        """Test to ensure players are properly represented in standings.

        Standings are analysed prior to any matches being reported.
        """
        self._register_players(["Melpomene Murray", "Randy Schwartz"])
        standings = player_standings()
        self._assert_standings_length(standings)
        self._assert_standings_values(standings)
        msg = "6. Newly registered players appear"
        print msg + " in the standings with no matches."
    def _assert_standings_values_after_delete_matches(self):
        standings = player_standings()
        self.assertEqual(len(
            standings), 4, "Match deletion should not change number of players \
                 in standings.")

        for (i, n, w, m) in standings:
            self.assertEqual(
                m, 0, "After deleting matches, players should have zero matches \
                 recorded.")
            self.assertEqual(
                w, 0, "After deleting matches, players should have zero wins \
                recorded.")
Exemple #8
0
def test_report_matches():
    '''This function tests to see if after a match the players' standing
    have been updated.'''
    tournament.delete_matches()
    tournament.delete_players()
    tournament.register_player("Bruno Walton")
    tournament.register_player("Boots O'Neal")
    tournament.register_player("Cathy Burton")
    tournament.register_player("Diane Grant")
    standings = tournament.player_standings()
    [id1, id2, id3, id4] = [row[0] for row in standings]
    tournament.report_match(id1, id2)
    tournament.report_match(id3, id4)
    standings = tournament.player_standings()
    for (i, n, w, m) in standings:
        if m != 1:
            raise ValueError("Each player should have one match recorded.")
        if i in (id1, id3) and w != 1:
            raise ValueError("Each match winner should have one win recorded.")
        elif i in (id2, id4) and w != 0:
            raise ValueError("Each match loser should have zero wins "
                             "recorded.")
    print "7. After a match, players have updated standings."
    def _assert_standings_values_after_delete_matches(self):
        standings = player_standings()
        self.assertEqual(
            len(standings), 4,
            "Match deletion should not change number of players \
                 in standings.")

        for (i, n, w, m) in standings:
            self.assertEqual(
                m, 0,
                "After deleting matches, players should have zero matches \
                 recorded.")
            self.assertEqual(
                w, 0, "After deleting matches, players should have zero wins \
                recorded.")
    def test_prevent_rematches(self):
        """Test that the system does not allow rematches.

        Test that the system prevent matches between a player and himself.
        """
        self._register_players(
            ["Bruno Walton", "Boots O'Neal", "Cathy Burton", "Diane Grant"])

        standings = player_standings()
        [id1, id2, id3, id4] = [row[0] for row in standings]
        report_match(id1, id2)
        report_match(id3, id4)
        self.assertRaises(DatabaseError, report_match(id2, id1))
        self.assertRaises(DatabaseError, report_match(id2, id2))
        print "11. Rematches are properly prevented."
    def test_prevent_rematches(self):
        """Test that the system does not allow rematches.

        Test that the system prevent matches between a player and himself.
        """
        self._register_players(
            ["Bruno Walton", "Boots O'Neal", "Cathy Burton", "Diane Grant"])

        standings = player_standings()
        [id1, id2, id3, id4] = [row[0] for row in standings]
        report_match(id1, id2)
        report_match(id3, id4)
        self.assertRaises(DatabaseError, report_match(id2, id1))
        self.assertRaises(DatabaseError, report_match(id2, id2))
        print "11. Rematches are properly prevented."
    def test_report_matches(self):
        """Test that matches are reported properly.

        Test to confirm matches are deleted properly.
        """
        self._register_players(
            ["Bruno Walton", "Boots O'Neal", "Cathy Burton", "Diane Grant"])

        standings = player_standings()
        [id1, id2, id3, id4] = [row[0] for row in standings]
        report_match(id1, id2)
        report_match(id3, id4)
        self._assert_standings_values_after_first_round(id1, id2, id3, id4)
        print "7. After a match, players have updated standings."

        delete_matches()
        self._assert_standings_values_after_delete_matches()
        print "8. After match deletion, player standings are properly reset."
        print "9. Matches are properly deleted."
    def test_report_matches(self):
        """Test that matches are reported properly.

        Test to confirm matches are deleted properly.
        """
        self._register_players(
            ["Bruno Walton", "Boots O'Neal", "Cathy Burton", "Diane Grant"])

        standings = player_standings()
        [id1, id2, id3, id4] = [row[0] for row in standings]
        report_match(id1, id2)
        report_match(id3, id4)
        self._assert_standings_values_after_first_round(id1, id2, id3, id4)
        print "7. After a match, players have updated standings."

        delete_matches()
        self._assert_standings_values_after_delete_matches()
        print "8. After match deletion, player standings are properly reset."
        print "9. Matches are properly deleted."
Exemple #14
0
    def test_report_match_with_tie(self):
        """Test reporting a match tie."""
        tournament_id = tournament.register_tournament(
            "Test Matches With Tie Tournament", 2)
        player_names = ("Bruno Walton", "Boots O'Neal")
        for player_name in player_names:
            tournament.register_player_in_tournament(
                tournament.register_player(player_name), tournament_id)

        standings = tournament.player_standings_by_tournament(tournament_id)
        player1, player2 = [row[0] for row in standings]
        tournament.report_match(player1, player2, tournament_id, tie=True)

        standings = tournament.player_standings()
        for id, name, wins, matches in standings:
            # Each player should have one match recorded
            self.assertEqual(matches, 1)
            # Each match winner should have one win recorded
            self.assertEqual(wins, 1)
        print "* After a match tie, tied players both have wins."
    def test_pairings(self):
        """Test that pairings are generated properly.

        Test this before and after match reporting.
        """
        players = ["Twilight Sparkle", "Fluttershy", "Applejack", "Pinkie Pie",
                   "Rarity", "Rainbow Dash", "Princess Celestia",
                   "Princess Luna"]
        self._register_players(players)

        standings = player_standings()
        [id1, id2, id3, id4, id5, id6, id7, id8] = [row[0]
                                                    for row in standings]
        self._assert_pairings_length()

        self._register_first_round(id1, id2, id3, id4, id5, id6, id7, id8)

        pairings = self._assert_pairings_length()
        self._assert_pairings_after_first_round(
            pairings, id1, id2, id3, id4, id5, id6, id7, id8)

        print "10. After one match, players with one win are properly paired."
    def stats(self):
        """Display player_standings.

         Id | Name | Wins | Matches
         1 | Player 1 | 1 | 1
         2 | Player 2 | 0 | 1

        Returns:
            first player's name
        """
        standings = player_standings()

        print '----------------------------'
        print 'Id | Name | Wins | Matches'
        print '----------------------------'
        j = 0
        while j < self.NR_OF_PLAYERS:
            print str(standings[j][0]) + " | " + str(standings[j][1]) + " | " \
                + str(standings[j][2]) + " | " + str(standings[j][3])
            j += 1

        return standings[0][1]
    def stats(self):
        """Display player_standings.

         Id | Name | Wins | Matches
         1 | Player 1 | 1 | 1
         2 | Player 2 | 0 | 1

        Returns:
            first player's name
        """
        standings = player_standings()

        print '----------------------------'
        print 'Id | Name | Wins | Matches'
        print '----------------------------'
        j = 0
        while j < self.NR_OF_PLAYERS:
            print str(standings[j][0]) + " | " + str(standings[j][1]) + " | " \
                + str(standings[j][2]) + " | " + str(standings[j][3])
            j += 1

        return standings[0][1]
    def test_pairings(self):
        """Test that pairings are generated properly.

        Test this before and after match reporting.
        """
        players = [
            "Twilight Sparkle", "Fluttershy", "Applejack", "Pinkie Pie",
            "Rarity", "Rainbow Dash", "Princess Celestia", "Princess Luna"
        ]
        self._register_players(players)

        standings = player_standings()
        [id1, id2, id3, id4, id5, id6, id7,
         id8] = [row[0] for row in standings]
        self._assert_pairings_length()

        self._register_first_round(id1, id2, id3, id4, id5, id6, id7, id8)

        pairings = self._assert_pairings_length()
        self._assert_pairings_after_first_round(pairings, id1, id2, id3, id4,
                                                id5, id6, id7, id8)

        print "10. After one match, players with one win are properly paired."
Exemple #19
0
def test_pairings():
    '''This tests to see if match pairings work properly.'''
    tournament.delete_matches()
    tournament.delete_players()
    tournament.register_player("Twilight Sparkle")
    tournament.register_player("Fluttershy")
    tournament.register_player("Applejack")
    tournament.register_player("Pinkie Pie")
    standings = tournament.player_standings()
    [id1, id2, id3, id4] = [row[0] for row in standings]
    tournament.report_match(id1, id2)
    tournament.report_match(id3, id4)
    pairings = tournament.swiss_pairings()
    if len(pairings) != 2:
        raise ValueError(
            "For four players, swiss_Pairings should return two pairs.")
    [(pid1, pname1, pid2, pname2), (pid3, pname3, pid4, pname4)] = pairings
    correct_pairs = set([frozenset([id1, id3]), frozenset([id2, id4])])
    actual_pairs = set([frozenset([pid1, pid2]), frozenset([pid3, pid4])])
    if correct_pairs != actual_pairs:
        raise ValueError(
            "After one match, players with one win should be paired.")
    print "8. After one match, players with one win are paired."
Exemple #20
0
def test_standings_before_matches():
    '''This function tests if newly registred players appear in the
    standings without any matches'''
    tournament.delete_matches()
    tournament.delete_players()
    tournament.register_player("Melpomene Murray")
    tournament.register_player("Randy Schwartz")
    standings = tournament.player_standings()
    if len(standings) < 2:
        raise ValueError("Players should appear in player_standings even "
                         "before they have played any matches.")
    elif len(standings) > 2:
        raise ValueError("Only registered players should appear in standings.")
    if len(standings[0]) != 4:
        raise ValueError("Each player_standings row should have four columns.")
    [(id1, name1, wins1, matches1), (id2, name2, wins2, matches2)] = standings
    if matches1 != 0 or matches2 != 0 or wins1 != 0 or wins2 != 0:
        raise ValueError(
            "Newly registered players should have no matches or wins.")
    if set([name1, name2]) != set(["Melpomene Murray", "Randy Schwartz"]):
        raise ValueError("Registered players' names should appear in "
                         "standings, even if they have no matches played.")
    print "6. Newly registered players appear in the standings "\
          "with no matches."