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); }
public void It_Should_Return_WhiteForEveryCorrectColourAtIncorrectPosition_When_Given_ValidGuesses(List <Peg> guess, List <Feedback> expectedFeedback) { //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); code.GenerateSecretCode(); //act var feedback = code.CheckGuess(guess); //assert Assert.Equal(expectedFeedback, feedback); }
public void It_Should_Return_A_KnownSecretCode_When_A_StaticCodeGeneratorIsUsed() { //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); //act code.GenerateSecretCode(); //assert var expectedSecretCode = new List <Peg> { Peg.Red, Peg.Blue, Peg.Green, Peg.Yellow }; Assert.True(code.SecretCode.SequenceEqual(expectedSecretCode)); }
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); }
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); }