Пример #1
0
        public void It_Should_SetIsWinnerAndIsGameOver_ToTrue_When_GuessIsCorrect(List <Peg> guess, bool expectedIsWinner, bool expectedIsGameOver)
        {
            //arrange
            var codeGenerator = new CodeGenerator(new List <Peg> {
                Peg.Red, Peg.Blue, Peg.Green, Peg.Yellow
            });
            var nonRandomizer = new NonRandomizer();
            var code          = new CodeChecker(codeGenerator, nonRandomizer);
            var config        = new MastermindConfig
            {
                [DataConstants.CodeLength] = 4, [DataConstants.NumberOfColours] = 6, [DataConstants.NumberOfTurns] = 8
            };
            var game = new Game(config, code);

            game.StartNewGame();


            //act
            var feedback = game.CheckGuess(guess);

            game.UpdateGame(guess, feedback);

            //assert
            Assert.Equal(expectedIsWinner, game.IsWinner);
            Assert.Equal(expectedIsGameOver, game.IsGameOver);
        }
Пример #2
0
        public void It_Should_Return_A_SecretCodeWithALengthOfFour_When_CodeLengthInConfigIsFour()
        {
            //arrange
            var config = new MastermindConfig
            {
                [DataConstants.CodeLength] = 4, [DataConstants.NumberOfColours] = 6, [DataConstants.NumberOfTurns] = 8
            };
            var randomCodeGenerator = new RandomCodeGenerator(config);

            //act
            var secretCode = randomCodeGenerator.GenerateSecretCode();

            //assert
            Assert.Equal(4, secretCode.Count);
        }
        public void It_Should_Throw_An_InvalidInputException_When_Given_InvalidInput(string input, string errorMessage)
        {
            //arrange
            var config = new MastermindConfig
            {
                [DataConstants.CodeLength] = 4, [DataConstants.NumberOfColours] = 6, [DataConstants.NumberOfTurns] = 8
            };
            var consoleInputProcessor = new ConsoleInputProcessor(config);

            //act
            Action actual = () => consoleInputProcessor.Process(input);


            //assert
            var exception = Assert.Throws <InvalidInputException>(actual);

            Assert.Equal(errorMessage, exception.Message);
        }
Пример #4
0
        public void It_Should_Return_A_SecretCodeOfColouredPegsWithFlagsFiveOrLess_When_NumberOfColoursInConfigIsSix()
        {
            //arrange
            var config = new MastermindConfig
            {
                [DataConstants.CodeLength] = 4, [DataConstants.NumberOfColours] = 6, [DataConstants.NumberOfTurns] = 8
            };
            var randomCodeGenerator = new RandomCodeGenerator(config);

            //act
            var secretCode = randomCodeGenerator.GenerateSecretCode();

            //assert
            foreach (var peg in secretCode)
            {
                Assert.True(Enum.IsDefined(typeof(Peg), peg) && (int)peg < config[DataConstants.NumberOfColours]);
            }
        }
        public void It_Should_Process_Input_When_Given_ValidInput()
        {
            //arrange
            var config = new MastermindConfig
            {
                [DataConstants.CodeLength] = 4, [DataConstants.NumberOfColours] = 6, [DataConstants.NumberOfTurns] = 8
            };

            var consoleInputProcessor = new ConsoleInputProcessor(config);

            //act
            var input = "Blue, Red, Green, Red";
            var guess = consoleInputProcessor.Process(input);

            //assert
            var expectedGuess = new List <Peg> {
                Peg.Blue, Peg.Red, Peg.Green, Peg.Red
            };

            Assert.Equal(expectedGuess, guess);
        }
Пример #6
0
        public void It_Should_SetIsGameOver_ToTrue_When_MaxNumberOfGuessesAreReached(int numberOfTurns, bool expectedIsGameOver)
        {
            //arrange
            var codeGenerator = new CodeGenerator(new List <Peg> {
                Peg.Red, Peg.Blue, Peg.Green, Peg.Yellow
            });
            var nonRandomizer = new NonRandomizer();
            var code          = new CodeChecker(codeGenerator, nonRandomizer);
            var config        = new MastermindConfig
            {
                [DataConstants.CodeLength] = 4, [DataConstants.NumberOfColours] = 6, [DataConstants.NumberOfTurns] = 8
            };
            var game = new Game(config, code);

            game.StartNewGame();


            for (var i = 0; i < numberOfTurns; i++)
            {
                var guess = new List <Peg> {
                    Peg.Blue, Peg.Orange, Peg.Orange, Peg.Yellow
                };
                var feedback = game.CheckGuess(guess);
                game.UpdateGame(guess, feedback);
            }


            //act
            var finalGuess = new List <Peg> {
                Peg.Orange, Peg.Orange, Peg.Orange, Peg.Orange
            };
            var finalFeedback = game.CheckGuess(finalGuess);

            game.UpdateGame(finalGuess, finalFeedback);



            //assert
            Assert.Equal(expectedIsGameOver, game.IsGameOver);
        }
Пример #7
0
        public void It_Should_Contain_AListOfTurns_When_AGuessIsChecked()
        {
            //arrange
            var codeGenerator = new CodeGenerator(new List <Peg> {
                Peg.Red, Peg.Blue, Peg.Green, Peg.Yellow
            });
            var nonRandomizer = new NonRandomizer();
            var code          = new CodeChecker(codeGenerator, nonRandomizer);
            var config        = new MastermindConfig
            {
                [DataConstants.CodeLength] = 4, [DataConstants.NumberOfColours] = 6, [DataConstants.NumberOfTurns] = 8
            };
            var game = new Game(config, code);

            game.StartNewGame();

            //act
            var guess = new List <Peg> {
                Peg.Blue, Peg.Orange, Peg.Orange, Peg.Yellow
            };
            var feedback = game.CheckGuess(guess);

            game.UpdateGame(guess, feedback);

            //assert
            var expectedTurn = new Turn(
                new List <Peg> {
                Peg.Blue, Peg.Orange, Peg.Orange, Peg.Yellow
            },
                new List <Feedback> {
                Feedback.Black, Feedback.White
            });

            var turn = game.Turns[0];

            turn.Should().BeEquivalentTo(expectedTurn);
        }
Пример #8
0
 public ConsoleInputProcessor(MastermindConfig mastermindConfig)
 {
     _mastermindConfig = mastermindConfig;
 }
Пример #9
0
 public Game(MastermindConfig config, CodeChecker codeChecker)
 {
     _config        = config;
     _codeChecker   = codeChecker;
     RemainingTurns = config[DataConstants.NumberOfTurns];
 }
 public RandomCodeGenerator(MastermindConfig mastermindConfiguration)
 {
     _config = mastermindConfiguration;
 }
Пример #11
0
 public MastermindConfigBuilder()
 {
     MastermindConfig = new MastermindConfig();
 }