Ejemplo n.º 1
0
        public void SingleEliminationHandlesManyCompetitorsWell()
        {
            IPairingsGenerator pg = new EliminationTournament(1);

            for (int i = 30; i <= 40; i++)
            {
                List <TournamentTeam>  teams  = new List <TournamentTeam>(CreateTeams(i));
                List <TournamentRound> rounds = new List <TournamentRound>();

                Dictionary <long, string> teamNames = new Dictionary <long, string>();
                foreach (var team in teams)
                {
                    teamNames.Add(team.TeamId, "Team#" + team.TeamId);
                }

                TournamentNameTable nameTable = new TournamentNameTable(teamNames);

                try
                {
                    RunTournament(pg, teams, rounds, false, nameTable);

                    DisplayTournamentRounds(rounds);
                    DisplayTournamentRankings(pg.GenerateRankings());
                }
                catch (InvalidTournamentStateException)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public void SingleEliminationLastPersonNeverGetsABye()
        {
            IPairingsGenerator pg = new EliminationTournament(1);

            for (int i = 2; i <= 33; i++)
            {
                List <TournamentTeam>  teams  = new List <TournamentTeam>(CreateTeams(i));
                List <TournamentRound> rounds = new List <TournamentRound>();

                pg.LoadState(teams, rounds);

                TournamentTeam targetTeam = teams[teams.Count - 1];

                TournamentRound round = pg.CreateNextRound(null);

                var targetTeamPairings = from p in round.Pairings
                                         where p.TeamScores.Where(ts => ts.Team.TeamId == targetTeam.TeamId).Any()
                                         select p;

                var pairingsThatAreByes = from ttp in targetTeamPairings
                                          where ttp.TeamScores.Count() == 1
                                          select ttp;

                if (pairingsThatAreByes.Any())
                {
                    Assert.Fail();
                }
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var p = new StandardTournamentsPluginEnumerator();

            var factories = from f in p.EnumerateFactories()
                            let pf = f as IPairingsGeneratorFactory
                                     where pf != null
                                     select pf;

            generator = (EliminationTournament)factories.ToList()[0].Create();

            teams.Add(new User(0, 100));
            teams.Add(new User(1, 100));


            generator.Reset();
            generator.LoadState(teams, rounds);
            // add winner
            TournamentRound round = generator.CreateNextRound(null);

            round.Pairings[0].TeamScores[0].Score = new HighestPointsScore(200);
            round.Pairings[0].TeamScores[1].Score = new HighestPointsScore(100);

            rounds.Add(round);

            var standings = generator.GenerateRankings();

            generator.Reset();
            generator.LoadState(teams, rounds);
            round = generator.CreateNextRound(null);
            Console.Read();
        }
Ejemplo n.º 4
0
        public void DoubleEliminationLongTournament()
        {
            IPairingsGenerator pg = new EliminationTournament(2);

            List <TournamentTeam>  teams  = new List <TournamentTeam>(CreateTeams(5));
            List <TournamentRound> rounds = new List <TournamentRound>();

            pg.LoadState(teams, rounds);
            TournamentRound round1 = pg.CreateNextRound(null);

            round1.Pairings[0].TeamScores[0].Score = new HighestPointsScore(1);
            round1.Pairings[0].TeamScores[1].Score = new HighestPointsScore(2);
            round1.Pairings[1].TeamScores[0].Score = new HighestPointsScore(1);
            round1.Pairings[1].TeamScores[1].Score = new HighestPointsScore(2);
            rounds.Add(round1);
            pg.LoadState(teams, rounds);
            TournamentRound round2 = pg.CreateNextRound(null);

            round2.Pairings[0].TeamScores[0].Score = new HighestPointsScore(1);
            round2.Pairings[0].TeamScores[1].Score = new HighestPointsScore(2);
            rounds.Add(round2);
            pg.LoadState(teams, rounds);
            TournamentRound round3 = pg.CreateNextRound(null);

            round3.Pairings[0].TeamScores[0].Score = new HighestPointsScore(2);
            round3.Pairings[0].TeamScores[1].Score = new HighestPointsScore(1);
            round3.Pairings[1].TeamScores[0].Score = new HighestPointsScore(2);
            round3.Pairings[1].TeamScores[1].Score = new HighestPointsScore(1);
            rounds.Add(round3);
            pg.LoadState(teams, rounds);
            TournamentRound round4 = pg.CreateNextRound(null);

            round4.Pairings[0].TeamScores[0].Score = new HighestPointsScore(2);
            round4.Pairings[0].TeamScores[1].Score = new HighestPointsScore(1);
            rounds.Add(round4);
            pg.LoadState(teams, rounds);
            TournamentRound round5 = pg.CreateNextRound(null);

            round5.Pairings[0].TeamScores[0].Score = new HighestPointsScore(1);
            round5.Pairings[0].TeamScores[1].Score = new HighestPointsScore(2);
            rounds.Add(round5);
            pg.LoadState(teams, rounds);
            TournamentRound round6 = pg.CreateNextRound(null);

            round6.Pairings[0].TeamScores[0].Score = new HighestPointsScore(2);
            round6.Pairings[0].TeamScores[1].Score = new HighestPointsScore(1);
            rounds.Add(round6);

            RunTournament(pg, teams, rounds, false, null);

            DisplayTournamentRounds(rounds);
            DisplayTournamentRankings(pg.GenerateRankings());
        }
Ejemplo n.º 5
0
        public void SingleEliminationThrowsExceptionOnNullParameters()
        {
            IPairingsGenerator pg = new EliminationTournament(1);

            try
            {
                pg.LoadState(null, null);
                Assert.Fail();
            }
            catch (ArgumentNullException)
            {
            }
        }
Ejemplo n.º 6
0
        public void DoubleEliminationTieDisallowed()
        {
            IPairingsGenerator pg = new EliminationTournament(2);

            List <TournamentTeam>  teams  = new List <TournamentTeam>(CreateTeams(2));
            List <TournamentRound> rounds = new List <TournamentRound>();

            pg.LoadState(teams, rounds);
            TournamentRound round = pg.CreateNextRound(null);

            round.Pairings[0].TeamScores[0].Score = new HighestPointsScore(10);
            round.Pairings[0].TeamScores[1].Score = new HighestPointsScore(10);
            rounds.Add(round);

            try
            {
                RunTournament(pg, teams, rounds, false, null);
                Assert.Fail();
            }
            catch (InvalidTournamentStateException)
            {
                return;
            }
        }
Ejemplo n.º 7
0
        public void SingleEliminationHandlesOutOfOrderCompetitors()
        {
            for (int i = 0; i < 10; i++)
            {
                var teamNames = new Dictionary <long, string>();
                teamNames[0] = "A";
                teamNames[1] = "B";
                teamNames[2] = "C";
                teamNames[3] = "D";
                teamNames[4] = "E";
                teamNames[5] = "F";

                var teams = (from k in teamNames.Keys
                             orderby k
                             select new TournamentTeam(k, r.Next(1000))).ToList();

                var round1 = new TournamentRound(
                    new TournamentPairing(
                        new TournamentTeamScore(teams[0], Score(1)),
                        new TournamentTeamScore(teams[1], Score(2))),
                    new TournamentPairing(
                        new TournamentTeamScore(teams[2], Score(3)),
                        new TournamentTeamScore(teams[3], Score(4))));
                var round2 = new TournamentRound(
                    new TournamentPairing(
                        new TournamentTeamScore(teams[1], Score(5)),
                        new TournamentTeamScore(teams[3], Score(6))));
                var round3 = new TournamentRound(
                    new TournamentPairing(
                        new TournamentTeamScore(teams[4], Score(7)),
                        new TournamentTeamScore(teams[5], Score(8))));
                var round4 = new TournamentRound(
                    new TournamentPairing(
                        new TournamentTeamScore(teams[5], Score(9)),
                        new TournamentTeamScore(teams[3], Score(10))));

                var rounds = (new[] { round1, round2, round3, round4 }).ToList();

                IPairingsGenerator pg = new EliminationTournament(1);

                pg.LoadState(teams, rounds);
                Assert.IsNull(pg.CreateNextRound(null));
                DisplayTournamentRankings(pg.GenerateRankings());
            }

            for (int i = 0; i < 10; i++)
            {
                var teamNames = new Dictionary <long, string>();
                teamNames[0] = "A";
                teamNames[1] = "B";
                teamNames[2] = "C";
                teamNames[3] = "D";
                teamNames[4] = "E";
                teamNames[5] = "F";

                var teams = (from k in teamNames.Keys
                             orderby k
                             select new TournamentTeam(k, r.Next(1000))).ToList();

                var round1 = new TournamentRound(
                    new TournamentPairing(
                        new TournamentTeamScore(teams[0], Score(1)),
                        new TournamentTeamScore(teams[1], Score(2))),
                    new TournamentPairing(
                        new TournamentTeamScore(teams[2], Score(3)),
                        new TournamentTeamScore(teams[3], Score(4))));
                var round2 = new TournamentRound(
                    new TournamentPairing(
                        new TournamentTeamScore(teams[1], Score(5)),
                        new TournamentTeamScore(teams[4], Score(6))));
                var round3 = new TournamentRound(
                    new TournamentPairing(
                        new TournamentTeamScore(teams[3], Score(7)),
                        new TournamentTeamScore(teams[5], Score(8))));
                var round4 = new TournamentRound(
                    new TournamentPairing(
                        new TournamentTeamScore(teams[4], Score(9)),
                        new TournamentTeamScore(teams[5], Score(10))));

                var rounds = (new[] { round1, round2, round3, round4 }).ToList();

                IPairingsGenerator pg = new EliminationTournament(1);

                pg.LoadState(teams, rounds);
                Assert.IsNull(pg.CreateNextRound(null));
                DisplayTournamentRankings(pg.GenerateRankings());
            }
        }