Esempio n. 1
0
        public void ItGivesTwoPointsToEachPlayerIfEveryoneLost()
        {
            int losingRank = 2;
            List <PlayerRank> playerRanks = new List <PlayerRank>();

            playerRanks.Add(new PlayerRank
            {
                PlayerId = 11,
                GameRank = losingRank
            });
            playerRanks.Add(new PlayerRank
            {
                PlayerId = 132,
                GameRank = losingRank
            });
            playerRanks.Add(new PlayerRank
            {
                PlayerId = 13,
                GameRank = losingRank
            });
            playerRanks.Add(new PlayerRank
            {
                PlayerId = 135,
                GameRank = losingRank
            });

            Dictionary <int, int> actualPointsAwarded = PointsCalculator.CalculatePoints(playerRanks);

            Assert.That(actualPointsAwarded.All(x => x.Value == 2));
        }
Esempio n. 2
0
        public void ItWorksForOneWinnerAndTwoLosers()
        {
            List <PlayerRank> playerRanks = new List <PlayerRank>();
            int winningPlayerId1          = 123;
            int losingPlayerId1           = 124;
            int losingPlayerId2           = 456;

            playerRanks.Add(new PlayerRank
            {
                GameRank = FIRST_PLACE,
                PlayerId = winningPlayerId1
            });
            playerRanks.Add(new PlayerRank
            {
                GameRank = SECOND_PLACE,
                PlayerId = losingPlayerId1
            });
            playerRanks.Add(new PlayerRank
            {
                GameRank = SECOND_PLACE,
                PlayerId = losingPlayerId2
            });

            Dictionary <int, int> actualPointsAwarded = PointsCalculator.CalculatePoints(playerRanks);

            int expectedWinnerPoints = 15;
            int expectedLoserPoints  = 8;

            Assert.That(actualPointsAwarded[winningPlayerId1], Is.EqualTo(expectedWinnerPoints));
            Assert.That(actualPointsAwarded[losingPlayerId1], Is.EqualTo(expectedLoserPoints));
            Assert.That(actualPointsAwarded[losingPlayerId2], Is.EqualTo(expectedLoserPoints));
        }
        public void CalculatePoints_Test(int killedEnemies, int killedAllies, int multiplicator, int expectedPoints)
        {
            var pointsCalculator = new PointsCalculator();

            var points = pointsCalculator.CalculatePoints(killedEnemies, killedAllies, multiplicator);

            Assert.That(points, Is.EqualTo(expectedPoints));
        }
Esempio n. 4
0
        internal virtual List <PlayerGameResult> TransformNewlyCompletedGamePlayerRanksToPlayerGameResults(NewlyCompletedGame newlyCompletedGame)
        {
            var pointsDictionary = PointsCalculator.CalculatePoints(newlyCompletedGame.PlayerRanks);

            var playerGameResults = newlyCompletedGame.PlayerRanks
                                    .Select(playerRank => new PlayerGameResult()
            {
                PlayerId = playerRank.PlayerId,
                GameRank = playerRank.GameRank,
                NemeStatsPointsAwarded = pointsDictionary[playerRank.PlayerId],
                PointsScored           = playerRank.PointsScored
            })
                                    .ToList();

            return(playerGameResults);
        }
Esempio n. 5
0
        public void ItWorksForTwoWinnersTwoSecondPlayerAndOneLastPlace()
        {
            List <PlayerRank> playerRanks = new List <PlayerRank>();
            int winningPlayerId1          = 100;
            int winningPlayerId2          = 101;
            int secondPlacePlayer1        = 200;
            int secondPlacePlayer2        = 201;
            int thirdPlacePlayerId        = 300;

            playerRanks.Add(new PlayerRank
            {
                GameRank = FIRST_PLACE,
                PlayerId = winningPlayerId1
            });
            playerRanks.Add(new PlayerRank
            {
                GameRank = FIRST_PLACE,
                PlayerId = winningPlayerId2
            });
            playerRanks.Add(new PlayerRank
            {
                GameRank = SECOND_PLACE,
                PlayerId = secondPlacePlayer1
            });
            playerRanks.Add(new PlayerRank
            {
                GameRank = SECOND_PLACE,
                PlayerId = secondPlacePlayer2
            });
            playerRanks.Add(new PlayerRank
            {
                GameRank = THIRD_PLACE,
                PlayerId = thirdPlacePlayerId
            });

            Dictionary <int, int> actualPointsAwarded = PointsCalculator.CalculatePoints(playerRanks);

            int expectedFirstPlacePoints  = 18;
            int expectedSecondPlacePoints = 7;
            int expectedThirdPlacePoints  = 3;

            Assert.That(actualPointsAwarded[winningPlayerId1], Is.EqualTo(expectedFirstPlacePoints));
            Assert.That(actualPointsAwarded[winningPlayerId2], Is.EqualTo(expectedFirstPlacePoints));
            Assert.That(actualPointsAwarded[secondPlacePlayer1], Is.EqualTo(expectedSecondPlacePoints));
            Assert.That(actualPointsAwarded[secondPlacePlayer2], Is.EqualTo(expectedSecondPlacePoints));
            Assert.That(actualPointsAwarded[thirdPlacePlayerId], Is.EqualTo(expectedThirdPlacePoints));
        }
Esempio n. 6
0
        public void ItThrowsAnArgumentExceptionIfThereAreMoreThan25Players()
        {
            List <PlayerRank> playerRanks = new List <PlayerRank>();

            for (int i = 0; i < PlayerRankValidator.MAXIMUM_NUMBER_OF_PLAYERS + 1; i++)
            {
                playerRanks.Add(new PlayerRank
                {
                    PlayerId = i,
                    GameRank = i + 1
                });
            }

            Exception actualException = Assert.Throws <ArgumentException>(() => PointsCalculator.CalculatePoints(playerRanks));

            Assert.That(actualException.Message, Is.EqualTo("There can be no more than 25 players."));
        }
Esempio n. 7
0
        public void ItGivesOutTenPointsToEachPlayerWhenEveryoneWins()
        {
            List <PlayerRank> playerRanks = new List <PlayerRank>();

            for (int i = 0; i < 13; i++)
            {
                playerRanks.Add(new PlayerRank
                {
                    GameRank = FIRST_PLACE,
                    PlayerId = i
                });
            }

            Dictionary <int, int> actualPointsAwarded = PointsCalculator.CalculatePoints(playerRanks);

            Assert.That(actualPointsAwarded.All(x => x.Value == 10));
        }
Esempio n. 8
0
        public void ItThrowsAnArgumentExceptionIfAGivenPlayerHasMultipleRanks()
        {
            List <PlayerRank> playerRanks = new List <PlayerRank>();

            playerRanks.Add(new PlayerRank
            {
                PlayerId = 1,
                GameRank = 1
            });
            playerRanks.Add(new PlayerRank
            {
                PlayerId = 1,
                GameRank = 2
            });

            Exception actualException = Assert.Throws <ArgumentException>(() => PointsCalculator.CalculatePoints(playerRanks));

            Assert.That(actualException.Message, Is.EqualTo("Each player can only have one PlayerRank record but one or more players have duplicate PlayerRank records."));
        }
Esempio n. 9
0
        public void ItSetsnemeStatsPointsForEachPlayerGameResult()
        {
            int playerOneId               = 1;
            int playerTwoId               = 2;
            int playerOneGameRank         = 1;
            int playerTwoGameRank         = 2;
            List <PlayerRank> playerRanks = new List <PlayerRank>()
            {
                new PlayerRank()
                {
                    PlayerId = playerOneId,
                    GameRank = playerOneGameRank
                },
                new PlayerRank()
                {
                    PlayerId = playerTwoId,
                    GameRank = playerTwoGameRank
                }
            };
            NewlyCompletedGame newlyCompletedGame = new NewlyCompletedGame()
            {
                GameDefinitionId = gameDefinition.Id,
                PlayerRanks      = playerRanks
            };

            var pointsDictionary = PointsCalculator.CalculatePoints(playerRanks);

            int             playerOneExpectednemeStatsPoints = pointsDictionary[playerOneId];
            ApplicationUser user = new ApplicationUser();

            PlayedGame playedGame = autoMocker.ClassUnderTest.CreatePlayedGame(newlyCompletedGame, TransactionSource.WebApplication, this.currentUser);

            Assert.AreEqual(playerOneExpectednemeStatsPoints, playedGame.PlayerGameResults
                            .First(gameResult => gameResult.PlayerId == playerOneId)
                            .NemeStatsPointsAwarded);

            int playerTwoExpectednemeStatsPoints = pointsDictionary[playerTwoId];

            Assert.AreEqual(playerTwoExpectednemeStatsPoints, playedGame.PlayerGameResults
                            .First(gameResult => gameResult.PlayerId == playerTwoId)
                            .NemeStatsPointsAwarded);
        }
Esempio n. 10
0
        public void ItGivesAboutTenPointsPerPlayerWhenRanksClumped(int numberOfPlayers)
        {
            List <PlayerRank> playerRanks = new List <PlayerRank>();

            for (int i = 0; i < numberOfPlayers; i++)
            {
                playerRanks.Add(new PlayerRank
                {
                    GameRank = (i + 1) % 2,
                    PlayerId = i
                });
            }

            Dictionary <int, int> actualPointsAwarded = PointsCalculator.CalculatePoints(playerRanks);

            //each player could round up at most 1 integer value
            int maxPointsAwarded = PointsCalculator.POINTS_PER_PLAYER * numberOfPlayers + numberOfPlayers;

            Assert.That(actualPointsAwarded.Sum(x => x.Value), Is.InRange(PointsCalculator.POINTS_PER_PLAYER, maxPointsAwarded));
        }
Esempio n. 11
0
        private static void RunSeasonPredictions()
        {
            var seasons = new[]
            {
                Season.Season1819,
                Season.Season1920,
                Season.Season2021,
            };

            foreach (var season in seasons)
            {
                Console.WriteLine(Display.Season(season));

                var fixtures = FixtureRepository.GetAllCompletedFixtures(season);

                foreach (var predictionStrategy in PredictionStrategies)
                {
                    if (predictionStrategy.CanPredict(season))
                    {
                        var totalPoints = 0;

                        foreach (var fixture in fixtures)
                        {
                            var predicted = predictionStrategy.PredictScore(fixture, season);

                            var points = PointsCalculator.CalculatePoints(predicted, fixture.FinalScore);

                            totalPoints += points;
                        }

                        Console.WriteLine($"{predictionStrategy.Name}: {totalPoints}");
                    }
                }

                Console.WriteLine();
            }
        }