Exemplo n.º 1
0
        public void GetSelectedColourShould_GetCorrectColours_WhenUserInputNumbers()
        {
            var testInput               = new TestResponder(new[] { "1111" });
            var output                  = new ConsoleOutput();
            var solutionGenerator       = new NormalSolutionGenerator();
            var player                  = new Player("Lan", solutionGenerator);
            var secretSolutionGenerator = new SecretSolutionGenerator();
            var mastermind              = new Mastermind(secretSolutionGenerator);
            var rule = new Rule();
            var game = new Game(player, mastermind, testInput, output, rule);

            var expectedResult = new Colour[] { Colour.Red, Colour.Red, Colour.Red, Colour.Red };
            var actualResult   = game.UserSelectColours();

            Assert.Equal(expectedResult, actualResult);
        }
Exemplo n.º 2
0
        public void PlayShould_SetPlayerIsWinnerTrue_WhenSolutionIsCorrect()
        {
            var testInput               = new TestResponder(new[] { "1111", "2222", "1234" });
            var output                  = new ConsoleOutput();
            var solutionGenerator       = new NormalSolutionGenerator();
            var player                  = new Player("Lan", solutionGenerator);
            var secretSolutionGenerator = new MockSecretSolutionGenerator();
            var mastermind              = new Mastermind(secretSolutionGenerator);
            var rule = new Rule();
            var game = new Game(player, mastermind, testInput, output, rule);

            game.Start();
            game.Play();
            Assert.True(player.IsWinner);
            Assert.Equal(3, game.GuessCount);
        }
Exemplo n.º 3
0
        public void PlayShould_ThrowException_WhenInputLengthIsInvalid()
        {
            var testInput               = new TestResponder(new[] { "111", "2222", "1234" });
            var output                  = new ConsoleOutput();
            var solutionGenerator       = new NormalSolutionGenerator();
            var player                  = new Player("Lan", solutionGenerator);
            var secretSolutionGenerator = new MockSecretSolutionGenerator();
            var mastermind              = new Mastermind(secretSolutionGenerator);
            var rule = new Rule();
            var game = new Game(player, mastermind, testInput, output, rule);

            game.Start();
            var ex = Assert.Throws <Exception>(() => game.Play());

            Assert.Equal("you must pass 4 colours!", ex.Message);
        }
Exemplo n.º 4
0
        public void PlayShould_ThrowException_WhenTooManyTries()
        {
            var input = new string[61];

            for (int i = 0; i < 61; i++)
            {
                input[i] = "1111";
            }
            Assert.Equal(61, input.Length);
            var testInput               = new TestResponder(input);
            var output                  = new ConsoleOutput();
            var solutionGenerator       = new NormalSolutionGenerator();
            var player                  = new Player("Lan", solutionGenerator);
            var secretSolutionGenerator = new MockSecretSolutionGenerator();
            var mastermind              = new Mastermind(secretSolutionGenerator);
            var rule = new Rule();
            var game = new Game(player, mastermind, testInput, output, rule);

            game.Start();
            var ex = Assert.Throws <Exception>(() => game.Play());

            Assert.Equal("you have more than 60 tries!", ex.Message);
        }