コード例 #1
0
        public void AddSamePlayerToSameTeamTwice_ThrowsInvalidOperationException()
        {
            var playerIdentifier = new EloPlayerIdentifier();
            var player           = new EloPlayer(playerIdentifier, 1350);
            var team             = new EloTeam(player, true);

            Assert.Throws <InvalidOperationException>(() => team.AddPlayer(player));
        }
コード例 #2
0
        public void AddPlayerWithSameIdentifierToTwoTeams_ThrowsArgumentException()
        {
            var playerIdentifier = new EloPlayerIdentifier();
            var player1          = new EloPlayer(playerIdentifier, 1350);
            var player2          = new EloPlayer(playerIdentifier, 1330);

            Assert.Throws <ArgumentException>(() => new EloMatch(new[] { new EloTeam(player1, true), new EloTeam(player2, false) }));
        }
コード例 #3
0
        public void CreateMatchDynamically_AddSamePlayer_ThrowsArgumentException()
        {
            var match          = new EloMatch();
            var teamIdentifier = match.AddTeam(new EloTeam(true));
            var player         = new EloPlayer(1200);

            match.AddPlayerToTeam(teamIdentifier, player);
            Assert.Throws <ArgumentException>(() => match.AddPlayerToTeam(teamIdentifier, player));
        }
コード例 #4
0
        public void PlayerWithSameIdentifierAndRating_AssertEquality()
        {
            var identifier = new EloPlayerIdentifier(Guid.NewGuid());
            var rating     = new EloRating(1200);
            var player1    = new EloPlayer(identifier, rating);
            var player2    = new EloPlayer(identifier, rating);

            Assert.AreEqual(player1, player2);
            Assert.IsTrue(player1 == player2);
            Assert.IsTrue(player1.Equals(player2));
        }
コード例 #5
0
        public void SimpleMatch_Player1Wins()
        {
            var player1 = new EloPlayer(1200);
            var player2 = new EloPlayer(1300);
            var teams   = new List <EloTeam> {
                new EloTeam(player1, true), new EloTeam(player2, false)
            };
            var match          = new EloMatch(teams);
            var result         = match.Calculate();
            var player1EloDiff = result.GetRatingDifference(player1.Identifier);
            var player2EloDiff = result.GetRatingDifference(player2.Identifier);

            Assert.Greater(player1EloDiff, player2EloDiff);
        }
コード例 #6
0
        public void TwoTeamsWithSamePlayers_AssertEquality()
        {
            var playerIdentifier = new EloPlayerIdentifier();
            var rating           = new EloRating(1200);
            var player1          = new EloPlayer(playerIdentifier, rating);
            var player2          = new EloPlayer(playerIdentifier, rating);
            var teamIdentifier   = new EloTeamIdentifier();
            var team1            = new EloTeam(teamIdentifier, player1, true);
            var team2            = new EloTeam(teamIdentifier, player2, false);

            Assert.AreEqual(team1, team2);
            Assert.IsTrue(team1 == team2);
            Assert.IsTrue(team1.Equals(team2));
        }
コード例 #7
0
ファイル: EloMatch.cs プロジェクト: vegar/bomberjam-contest
        public IEloPlayer AddPlayer(int rank, float elo)
        {
            var player = new EloPlayer
            {
                Id        = this._players.Count,
                Rank      = rank,
                OldElo    = elo,
                NewElo    = elo,
                EloChange = 0
            };

            this._players.Add(player.Id, player);

            return(player);
        }
コード例 #8
0
        public void SimpleMatch_SetKFactorAs0_Player1Wins_NoEloGained()
        {
            var player1 = new EloPlayer(1200);
            var player2 = new EloPlayer(1300);
            var players = new List <EloTeam> {
                new EloTeam(player1, true), new EloTeam(player2, false)
            };
            var match = new EloMatch(players);

            match.SetKFactor(0);
            var result         = match.Calculate();
            var player1EloDiff = result.GetRatingDifference(player1.Identifier);
            var player2EloDiff = result.GetRatingDifference(player2.Identifier);

            Assert.AreEqual(0, player1EloDiff);
            Assert.AreEqual(0, player2EloDiff);
        }
コード例 #9
0
        public void AddPlayerToTwoTeams_ThrowsArgumentException()
        {
            var player = new EloPlayer(1350);

            Assert.Throws <ArgumentException>(() => new EloMatch(new[] { new EloTeam(player, true), new EloTeam(player, false) }));
        }