public void SwissResetMatches_RemovesPlayersFromAllMatchesAfterFirstRound()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 32; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i + 1);
                pList.Add(moq.Object);
            }
            IBracket b = new SwissBracket(pList);
            int      matchesPerRound = b.GetRound(1).Count;

            for (int i = 0; i < 3; ++i)
            {
                for (int n = 1; n <= matchesPerRound; ++n)
                {
                    b.SetMatchWinner(n + (i * matchesPerRound), PlayerSlot.Defender);
                }
            }

            b.ResetMatches();
            int matchesWithPlayers = 0;

            for (int n = 1; n < b.NumberOfMatches; ++n)
            {
                if (!(b.GetMatch(n).Players.Contains(null)))
                {
                    ++matchesWithPlayers;
                }
            }
            Assert.AreEqual(matchesPerRound, matchesWithPlayers);
        }
        public void AddSwissRound_MatchesWinnersAgainstEachOther()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 4; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i);
                pList.Add(moq.Object);
            }
            IBracket b = new SwissBracket(pList);
            int      firstRoundMatches = b.NumberOfMatches;

            for (int n = 1; n <= firstRoundMatches; ++n)
            {
                b.AddGame(n, 0, 1, PlayerSlot.Challenger);
            }

            Assert.IsTrue(b.GetMatch(1).Players[(int)(b.GetMatch(1).WinnerSlot)].Id == b.GetMatch(4).Players[(int)PlayerSlot.Defender].Id &&
                          b.GetMatch(2).Players[(int)(b.GetMatch(2).WinnerSlot)].Id == b.GetMatch(4).Players[(int)PlayerSlot.Challenger].Id);
        }
        public void SwissCreateBracket_GivesFirstRoundByeToTopSeed()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 9; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i + 3);
                pList.Add(moq.Object);
            }
            IBracket b = new SwissBracket(pList);

            // Match(1) is Player[second] vs Player[last]
            Assert.AreEqual(b.Players[1].Id,
                            b.GetMatch(1).Players[(int)PlayerSlot.Defender].Id);
        }
        public void SwissCreateBracket_UsesStandardSlideMatchups()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 8; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i);
                pList.Add(moq.Object);
            }
            IBracket b = new SwissBracket(pList);

            // Match(1) is Player[0] vs Player[4]
            Assert.AreEqual(b.Players[b.NumberOfPlayers() / 2].Id,
                            b.GetMatch(1).Players[(int)PlayerSlot.Challenger].Id);
        }
        public void SwissUpdateGame_ResetsNextRound_IfMatchWinnerChanges()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 9; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i + 1);
                pList.Add(moq.Object);
            }
            IBracket b = new SwissBracket(pList);
            int      matchesPerRound = b.GetRound(1).Count;

            for (int n = 1; n <= matchesPerRound; ++n)
            {
                b.AddGame(n, 10, 5, PlayerSlot.Defender);
            }
            b.SetMatchWinner(matchesPerRound + 1, PlayerSlot.Challenger);

            b.UpdateGame(1, 1, 5, 15, PlayerSlot.Challenger);
            Assert.IsFalse(b.GetMatch(matchesPerRound + 1).IsFinished);
        }