示例#1
0
        public void MakeCorrectInitialGuess(int numberOfPegs, int numberOfPegsPerLine, string expectedLineAsString)
        {
            // Arrange
            var expectedLine = expectedLineAsString.Split(' ').Select(s => int.Parse(s)).ToArray();
            var player       = new FiveGuessAlgorithmPlayer();
            var game         = new Game(numberOfPegs, numberOfPegsPerLine, 1);

            // Act
            var result = game.Play(player);

            // Assert
            Assert.Equal(expectedLine, result.GuessesAndResults.Single().Guess);
        }
示例#2
0
        public void WinGame()
        {
            // Arrange
            var player = new FiveGuessAlgorithmPlayer();

            // Act
            player.BeginGame(8, 4, 10);
            var guess1 = player.GetGuess();

            player.ResultFromPreviousGuess(0, 0);
            var guess2 = player.GetGuess();

            player.ResultFromPreviousGuess(4, 0);
            player.EndGame(true, 2, guess2);

            // Assert - The game must complete without errors
        }
示例#3
0
        public void LooseGame()
        {
            // Arrange
            var player = new FiveGuessAlgorithmPlayer();

            // Act
            player.BeginGame(9, 4, 2);
            var guess1 = player.GetGuess();

            player.ResultFromPreviousGuess(0, 0);
            var guess2 = player.GetGuess();

            player.ResultFromPreviousGuess(0, 0);
            var secret = Enumerable.Repeat(Enumerable.Range(0, 10).Except(guess1).Except(guess2).First(), 4);

            player.EndGame(false, 2, secret.ToArray());

            // Assert - The game must complete without errors
        }
示例#4
0
        public void WinAllGamesUsingMaximumFiveGuesses()
        {
            const int NumberOfDifferentPegs = 6;
            const int NumberOfPegsPerLine   = 4;
            const int MaxNumberOfGuesses    = 5;
            var       player = new FiveGuessAlgorithmPlayer();
            var       lines  = LineGenerator.GenerateAllLines(NumberOfDifferentPegs, NumberOfPegsPerLine);
            // it is too slow to test all lines
            // we only test on average 1% of all the different lines (roughly 13 out of 1296)
            var random = new Random();

            lines = lines.Where(l => random.Next(100) == 10).ToList();
            Assert.All(lines,
                       secret =>
            {
                var game   = new Game(NumberOfDifferentPegs, NumberOfPegsPerLine, MaxNumberOfGuesses, secret);
                var result = game.Play(player);
                Assert.True(result.WasTheSecretGuessed);
            });
        }