public void SwissResetMatchScore_RecalculatesRankings_IfMatchWinIsReversed() { List <IPlayer> pList = new List <IPlayer>(); for (int i = 0; i < 33; ++i) { Mock <IPlayer> moq = new Mock <IPlayer>(); moq.Setup(p => p.Id).Returns(i + 1); pList.Add(moq.Object); } IBracket b = new SwissBracket(pList, PairingMethod.Slide, 3); int matchesPerRound = b.GetRound(1).Count; for (int n = 1; n <= matchesPerRound; ++n) { b.SetMatchWinner(n, PlayerSlot.Challenger); } for (int n = 1; n < matchesPerRound; ++n) { b.AddGame(n + matchesPerRound, 25, 15, PlayerSlot.Defender); b.AddGame(n + matchesPerRound, 25, 15, PlayerSlot.Defender); } b.ResetMatchScore(matchesPerRound + 1); Assert.AreEqual(2, b.Rankings[0].Wins); }
public void SwissResetMatchScore_ClearsAllFutureRounds() { 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, PairingMethod.Slide, 3); int matchesPerRound = b.GetRound(1).Count; for (int i = 0; i < 3; ++i) { for (int n = 1; n <= matchesPerRound; ++n) { b.AddGame(n + (i * matchesPerRound), 1, 0, PlayerSlot.Defender); b.AddGame(n + (i * matchesPerRound), 1, 0, PlayerSlot.Defender); } } b.ResetMatchScore(1); bool roundTwoHasPlayers = b.GetRound(2) .Any(m => !(m.Players.Contains(null))); Assert.IsFalse(roundTwoHasPlayers); }
public void SwissResetMatchScore_FiresGamesDeletedEvents_WithAllGamesInClearedRound() { int deletedGames = 0; 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); b.GamesDeleted += delegate(object sender, BracketEventArgs e) { deletedGames += e.DeletedGameIDs.Count; }; b.MatchesModified += delegate(object sender, BracketEventArgs e) { deletedGames += e.DeletedGameIDs.Count; }; int matchesPerRound = b.GetRound(1).Count; for (int n = 1; n <= (2 + matchesPerRound); ++n) { b.AddGame(n, 2, 1, PlayerSlot.Defender); } b.ResetMatchScore(1); // Delete games: 1 from first match, 2 from second round (removed) Assert.AreEqual(1 + 2, deletedGames); }
public void SwissResetMatchScore_DeletesFollowingRound_IfMatchWinIsReversed() { 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, PairingMethod.Slide, 3); int matchesPerRound = b.NumberOfMatches; for (int n = 1; n <= matchesPerRound; ++n) { b.AddGame(n, 1, 0, PlayerSlot.Defender); b.AddGame(n, 1, 0, PlayerSlot.Defender); } b.ResetMatchScore(matchesPerRound); Assert.AreEqual(matchesPerRound, b.NumberOfMatches); }
public void AddSwissRound_GivesSecondRoundByeToTopSeed_ButDoesntRepeatBye() { List <IPlayer> pList = new List <IPlayer>(); for (int i = 0; i < 5; ++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.AreNotEqual(b.Players[0].Id, b.Rankings[0].Id); }
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 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); }