public void should_get_correct_bracket_height()
        {
            BracketGenerator bracket = new BracketGenerator();

            bracket.Participants.Add(new Participant()
            {
                Name = "Joe", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Rob", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Nate", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Stephen", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Justin", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Blake", Seed = null
            });

            Assert.AreEqual(2, bracket.BracketHeight);
        }
        public void should_get_correct_match_count_using_delegate_if_edge_case_matches()
        {
            BracketGenerator bracket = new BracketGenerator();

            bracket.Participants.Add(new Participant()
            {
                Name = "Joe", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Rob", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Nate", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Stephen", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Justin", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Blake", Seed = null
            });
            bracket.GenerateBracket();

            Assert.AreEqual(bracket.Participants.Count() - 1, bracket.FinalMatch.GetMatchCount());
        }
        public void should_assign_edge_case_participants_if_needed()
        {
            BracketGenerator bracket = new BracketGenerator();

            bracket.Participants.Add(new Participant()
            {
                Name = "Joe", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Rob", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Nate", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Stephen", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Justin", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Blake", Seed = null
            });

            bracket.SetBracketOrder();
            Assert.AreEqual(4, bracket.EdgeCaseParticipants.Count);
        }
        public void bracket_should_set_edge_case_participants()
        {
            BracketGenerator bracket = new BracketGenerator();

            var           orderedList = new List <Participant>();
            List <string> names       = new List <string>()
            {
                "Rob",
                "Joe",
                "Kamika",
                "Matthew",
                "Stephen",
                "George",
                "Nate",
                "Matt",
                "Jeff",
                "Shayla",
                "Kelly",
            };

            int count = 0;

            while (count < 11)
            {
                bracket.Participants.Add(new Participant()
                {
                    Name = names[count], Seed = count + 1
                });
                count += 1;
            }

            bracket.SetEdgeCaseParticipants(bracket.Participants);

            Assert.AreEqual(6, bracket.EdgeCaseParticipants.Count);
        }
        public void should_set_correct_winner()
        {
            BracketGenerator bracket = new BracketGenerator();

            bracket.Participants.Add(new Participant()
            {
                Name = "Joe", Seed = 1
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Rob", Seed = 4
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Nate", Seed = 2
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Stephen", Seed = 3
            });
            bracket.GenerateBracket();
            bracket.FinalMatch.SetMatchWinner("Joe", 1, bracket.BracketHeight);
            var winnerName = bracket.FinalMatch.GetMatchWinner(
                new List <string>()
            {
                "Joe", "Rob"
            }, 1, bracket.BracketHeight).Name;

            Assert.AreEqual("Joe", winnerName);
        }
        public void SampleLength2Test()
        {
            var writer    = new WriterMock();
            var generator = new BracketGenerator(writer);

            generator.Gen(2, 0, 0, "");
            Assert.AreEqual("(())", writer.GetLine());
            Assert.AreEqual("()()", writer.GetLine());
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            ITeamsRepository  teamsRepo        = new TeamsRepository();
            IBracketGenerator bracketGenerator = new BracketGenerator();
            IMatchupService   matchupService   = new MatchupService();
            IWinnersService   winnersService   = new WinnersService();

            var roundOf64Teams = teamsRepo.GetTeams();

            var roundOf64Matchups = matchupService.GetMatchups(roundOf64Teams);

            ValidateMatchupCount(32, roundOf64Matchups.Count);
            var roundOf64Winners = winnersService.PredictWinners(roundOf64Matchups);

            var roundOf32Matchups = matchupService.GetMatchups(roundOf64Winners);

            ValidateMatchupCount(16, roundOf32Matchups.Count);
            var roundOf32Winners = winnersService.PredictWinners(roundOf32Matchups);

            var sweetSixteenMatchups = matchupService.GetMatchups(roundOf32Winners);

            ValidateMatchupCount(8, sweetSixteenMatchups.Count);
            var sweetSixteenWinners = winnersService.PredictWinners(sweetSixteenMatchups);

            var eliteEightMatchups = matchupService.GetMatchups(sweetSixteenWinners);

            ValidateMatchupCount(4, eliteEightMatchups.Count);
            var eliteEightWinners = winnersService.PredictWinners(eliteEightMatchups);

            var finalFourMatchups = matchupService.GetMatchups(eliteEightWinners);

            ValidateMatchupCount(2, finalFourMatchups.Count);
            var finalFourWinners = winnersService.PredictWinners(finalFourMatchups);

            var championshipMatchup = matchupService.GetMatchups(finalFourWinners);

            ValidateMatchupCount(1, championshipMatchup.Count);
            var championshipWinner = winnersService.PredictWinners(championshipMatchup);

            var allMatchups = roundOf64Matchups.Concat(roundOf32Matchups).Concat(sweetSixteenMatchups)
                              .Concat(eliteEightMatchups).Concat(finalFourMatchups).Concat(championshipMatchup).ToList();

            var allWinners = roundOf64Winners.Concat(roundOf32Winners).Concat(sweetSixteenWinners)
                             .Concat(eliteEightWinners).Concat(finalFourWinners).Concat(championshipWinner).ToList();

            bracketGenerator.GenerateBracket(allMatchups, allWinners);

            Console.WriteLine("Your bracket has been generated. Press [enter] to exit.");
            Console.ReadLine();
        }
Esempio n. 8
0
        private void btn_generate_brackets_Click(object sender, EventArgs e)
        {
            if (PlayerRankings != null && PlayersAttending != null)
            {
                var uniquePlayerNames = PlayerRankings.Select(players => players.FullName).ToList();
                var missingPlayers    = PlayersAttending.Except(uniquePlayerNames);
                if (!missingPlayers.Any())
                {
                    var playersAttendingTournament = PlayerRankings.Where(x => PlayersAttending.Contains(x.FullName)).ToList();

                    var test = BracketGenerator.GenerateBrackets(playersAttendingTournament);
                }
            }
        }
Esempio n. 9
0
            public static void Test()
            {
                var participants = new[]
                {
                    new P(4, "Tanel"),
                    new P(2, "Peeter"),
                    new P(3, "Joonatan"),
                    new P(1, "Tanel"),
                    new P(5, "Peeter")
                };

                var gen      = new BracketGenerator();
                var provider = new EDRAStreetBracketProvider();
                var bracket  = gen.GenerateBracket(participants, x => x.Name, x => x.Value, provider, true);
            }
        public void bracket_should_put_edge_case_participants_in_correct_order()
        {
            BracketGenerator bracket = new BracketGenerator();

            var           orderedList = new List <Participant>();
            List <string> names       = new List <string>()
            {
                "Rob",
                "Joe",
                "Kamika",
                "Matthew",
                "Stephen",
                "George",
                "Nate",
                "Matt",
                "Jeff",
                "Shayla",
                "Kelly",
            };

            int count = 0;

            while (count < 11)
            {
                bracket.Participants.Add(new Participant()
                {
                    Name = names[count], Seed = count + 1
                });
                count += 1;
            }

            bracket.SetEdgeCaseParticipants(bracket.Participants);
            bracket.SetEdgeCaseOrderBySeed();

            orderedList.Add(bracket.EdgeCaseParticipants.ElementAt(4));
            orderedList.Add(bracket.EdgeCaseParticipants.ElementAt(1));
            orderedList.Add(bracket.EdgeCaseParticipants.ElementAt(2));
            orderedList.Add(bracket.EdgeCaseParticipants.ElementAt(3));
            orderedList.Add(bracket.EdgeCaseParticipants.ElementAt(5));
            orderedList.Add(bracket.EdgeCaseParticipants.ElementAt(0));


            var orderedStack = new Stack <Participant>(orderedList);

            Assert.AreEqual(orderedStack.Count, bracket.EdgeCaseParticipantsInBracketOrder.Count);
            Assert.AreEqual(orderedStack.ElementAt(4), bracket.EdgeCaseParticipantsInBracketOrder.ElementAt(4));
        }
        public void should_assign_seeds_to_randomized_participants()
        {
            BracketGenerator bracket = new BracketGenerator();

            bracket.Participants.Add(new Participant()
            {
                Name = "Joe", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Rob", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Nate", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Stephen", Seed = null
            });

            bracket.AssignSeeds();
            Assert.AreEqual(4, bracket.Participants[3].Seed);
        }
        public void should_assign_byes_if_needed()
        {
            BracketGenerator bracket = new BracketGenerator();

            bracket.Participants.Add(new Participant()
            {
                Name = "Joe", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Rob", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Nate", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Stephen", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Justin", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Blake", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Kamika", Seed = null
            });

            bracket.SetBracketOrder();
            Assert.AreEqual(1, bracket.Participants.Count(k => k.Name == "Bye"));
        }
        public void should_get_correct_bracket_height_for_ideal_bracket()
        {
            BracketGenerator bracket = new BracketGenerator();

            bracket.Participants.Add(new Participant()
            {
                Name = "Joe", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Rob", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Nate", Seed = null
            });
            bracket.Participants.Add(new Participant()
            {
                Name = "Stephen", Seed = null
            });

            Assert.AreEqual(2, bracket.BracketHeight);
            Assert.AreEqual(0, bracket.NumberOfByes);
        }
        public void bracket_should_put_seeded_participants_in_correct_order()
        {
            BracketGenerator bracket = new BracketGenerator();

            var           orderedList = new List <Participant>();
            List <string> names       = new List <string>()
            {
                "Rob",
                "Joe",
                "Kamika",
                "Matthew",
                "Stephen",
                "George",
                "Nate",
                "Matt",
                "Jeff",
                "Shayla",
                "Kelly",
                "Stephanie",
                "Blake",
                "Jim",
                "Reid",
                "Jake"
            };

            int count = 0;

            while (count < 16)
            {
                bracket.Participants.Add(new Participant()
                {
                    Name = names[count], Seed = count + 1
                });
                count += 1;
            }

            orderedList.Add(bracket.Participants.ElementAt(14));
            orderedList.Add(bracket.Participants.ElementAt(1));
            orderedList.Add(bracket.Participants.ElementAt(9));
            orderedList.Add(bracket.Participants.ElementAt(6));
            orderedList.Add(bracket.Participants.ElementAt(13));
            orderedList.Add(bracket.Participants.ElementAt(2));
            orderedList.Add(bracket.Participants.ElementAt(10));
            orderedList.Add(bracket.Participants.ElementAt(5));
            orderedList.Add(bracket.Participants.ElementAt(12));
            orderedList.Add(bracket.Participants.ElementAt(3));
            orderedList.Add(bracket.Participants.ElementAt(11));
            orderedList.Add(bracket.Participants.ElementAt(4));
            orderedList.Add(bracket.Participants.ElementAt(8));
            orderedList.Add(bracket.Participants.ElementAt(7));
            orderedList.Add(bracket.Participants.ElementAt(15));
            orderedList.Add(bracket.Participants.ElementAt(0));

            bracket.SetBracketOrder();
            count = bracket.ParticipantsInBracketOrder.Count;
            var orderedStack = new Stack <Participant>(orderedList);

            Assert.AreEqual(orderedStack.Count, bracket.ParticipantsInBracketOrder.Count);
            Assert.AreEqual(orderedStack.ElementAt(4), bracket.ParticipantsInBracketOrder.ElementAt(4));
            Assert.AreEqual(orderedStack.ElementAt(0), bracket.ParticipantsInBracketOrder.ElementAt(0));
            Assert.AreEqual(orderedStack.ElementAt(count - 1), bracket.ParticipantsInBracketOrder.ElementAt(count - 1));
        }
        public void bracket_height_should_be_zero_if_no_participants_exist()
        {
            BracketGenerator bracket = new BracketGenerator();

            Assert.AreEqual(0, bracket.BracketHeight);
        }