public void SwissResetMatchScore_FiresMatchesModifiedEvent_WithOnlyOneMatchModel() { 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.SetMatchWinner(n, PlayerSlot.Challenger); } int matchesModified = 0; b.MatchesModified += delegate(object sender, BracketEventArgs e) { matchesModified += e.UpdatedMatches.Count; }; b.ResetMatchScore(1); Assert.AreEqual(1, matchesModified); }
public void SwissResetMatches_ReAddsAutowinToPlayerWithBye() { 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 i = 0; i < 2; ++i) { for (int n = 1; n <= matchesPerRound; ++n) { b.SetMatchWinner(n + (i * matchesPerRound), PlayerSlot.Defender); } } b.ResetMatches(); int rIndex = b.Rankings.FindIndex(r => r.Id == b.Players[0].Id); Assert.AreEqual(1, b.Rankings[rIndex].Wins); }
public void SwissAddGame_FiresMatchesModifiedEvent_WithAllMatchesAffectedAndNextRound() { int matchesModified = 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.MatchesModified += delegate(object sender, BracketEventArgs e) { matchesModified += e.UpdatedMatches.Count; }; int matchesPerRound = b.GetRound(1).Count; for (int i = 0; i < 2; ++i) { for (int n = 1; n <= matchesPerRound; ++n) { b.SetMatchWinner(n + (matchesPerRound * i), PlayerSlot.Challenger); } } Assert.AreEqual(2 * 2 * matchesPerRound, matchesModified); }
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 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 SwissReplacePlayer_ReplacesPlayerIDinByesList() { List <IPlayer> pList = new List <IPlayer>(); for (int i = 0; i < 7; ++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 pId = 50; Mock <IPlayer> player = new Mock <IPlayer>(); player.Setup(p => p.Id).Returns(pId); b.ReplacePlayer(player.Object, 0); // 0-index had a first-round bye. List <IMatch> round1 = b.GetRound(1); foreach (IMatch match in round1) { b.SetMatchWinner(match.MatchNumber, PlayerSlot.Defender); } // Second round is now populated. // If new player was correctly added to the Byes list... // He will be in exactly 1 second-round match: List <IMatch> round2 = b.GetRound(2); Assert.AreEqual(1, round2.Where(m => m.Players.Select(p => p.Id).Contains(pId)).ToList().Count); }
public void AddSwissRound_PopulatesSecondRoundWhenFirstFinishes() { 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); List <IMatch> round1 = b.GetRound(1); foreach (IMatch match in round1) { b.SetMatchWinner(match.MatchNumber, PlayerSlot.Defender); } Assert.IsFalse(b.GetRound(2).Select(m => m.Players).Contains(null)); }
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); }