Пример #1
0
        public void Should_Pass_When_ExcpectedResultsReturnedFor_ExpectationToWin()
        {
            //The two scores are the same, so it's 50/50 chance
            double result = CalculateRating.ExpectationToWin(100, 100);

            Assert.AreEqual(0.5, result);
        }
Пример #2
0
        public void Should_Pass_When_ExcpectedResultsReturnedFor_Calculate()
        {
            // Same score entered, Score difference should be 16
            var expected = CalculateRating.CalculateScoreDifference(100, 100);

            Assert.AreEqual(expected, 16);
        }
Пример #3
0
        /// <summary>
        /// Receive the winner and the loser Ids. Calculate the score and update it in each of them
        /// </summary>
        /// <param name="idWinner"></param>
        /// <param name="idLoser"></param>
        /// <returns>HttpStatusCode Ok</returns>
        public ActionResult UpdateScore(string idWinner, string idLoser)
        {
            log.Info(String.Format("In : UpdateScore : idWinner = {0} ; idLoser={1}", idWinner, idLoser));
            try
            {
                var winnerCat = CatComparerService.GetCat(idWinner);
                var loserCat  = CatComparerService.GetCat(idLoser);

                var scoresDifferance = CalculateRating.CalculateScoreDifference(winnerCat.Score, loserCat.Score);

                winnerCat.Score += scoresDifferance;
                loserCat.Score  -= scoresDifferance;

                CatComparerService.UpdateScoreOfCat(winnerCat);
                CatComparerService.UpdateScoreOfCat(loserCat);
            }
            catch (Exception ex)
            {
                log.Error("Exception : UpdateScore : {0}", ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, String.Format("Unable to Update Score : {0}", ex.Message)));
            }
            finally
            {
                log.Info("Out : UpdateScore");
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }