/// <inheritdoc />
        public void ValidateTeam(int teamId)
        {
            int dimensions = _matrixProvider.GetDimensions();

            if (!(teamId < dimensions) || teamId < 0)
            {
                throw new InvalidTeamIndexException(teamId);
            }
        }
        public void ShouldNot_ValidateTeam_ForGreaterThanDimensionInput()
        {
            //arrange
            int               dimensions       = 2;
            int               teamId           = 2;
            IMatrixProvider   matrixProvider   = A.Fake <IMatrixProvider>();
            IValidatorService validatorService = new ValidatorService(matrixProvider);

            A.CallTo(() => matrixProvider.GetDimensions()).Returns(dimensions);

            //act
            Action action = () => validatorService.ValidateTeam(teamId);

            //assert
            action.Should().Throw <InvalidTeamIndexException>();
        }
 /// <summary>
 /// Instantiates a ColleyMatrixService object
 /// </summary>
 /// <param name="matrixProvider">An abstraction for the underlying sparse matrix</param>
 /// <param name="validatorService">A service for validating input and output</param>
 public ColleyMatrixService(IMatrixProvider matrixProvider, IValidatorService validatorService)
 {
     _matrixProvider   = matrixProvider;
     _validatorService = validatorService;
     _dimensions       = _matrixProvider.GetDimensions();
     _teams            = new List <Team>();
     for (int teamId = 0; teamId < _dimensions; teamId++)
     {
         _teams.Add(new Team()
         {
             TeamId = teamId,
             Wins   = 0,
             Losses = 0,
             //initialize all ratings to 1
             ColleyRating = 1
         });
     }
 }
Beispiel #4
0
        public void Should_SimluateGame_ForStandardInput()
        {
            //arrange
            int               dimensions       = 2;
            int               winnerId         = 0;
            int               loserId          = 1;
            IMatrixProvider   matrixProvider   = A.Fake <IMatrixProvider>();
            IValidatorService validatorService = A.Fake <IValidatorService>();

            A.CallTo(() => matrixProvider.GetDimensions()).Returns(dimensions);
            IColleyMatrixService colleyMatrixService = new ColleyMatrixService(matrixProvider, validatorService);

            //act
            colleyMatrixService.SimulateGame(winnerId, loserId);

            //assert
            A.CallTo(() => validatorService.ValidateTeam(winnerId)).MustHaveHappened();
            A.CallTo(() => validatorService.ValidateTeam(loserId)).MustHaveHappened();
        }