Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void CreateHintBasedOnPlayerSolutionShould_CreateCorrectHint2Black_BasedOnPlayerSolution()
        {
            var secretSolutionGenerator = new MockSecretSolutionGenerator();
            var mastermind = new Mastermind(secretSolutionGenerator);

            mastermind.SetSecretSolution(_colours);
            var peg1     = new Peg(Colour.Red);
            var peg2     = new Peg(Colour.Blue);
            var peg3     = new Peg(Colour.Yellow);
            var peg4     = new Peg(Colour.Yellow);
            var solution = new[] { peg1, peg2, peg3, peg4 };
            var hint     = mastermind.CreateHintBasedOnPlayerSolution(solution);

            Assert.Equal(Value.Black, hint[0].Value);
            Assert.Equal(Value.Black, hint[1].Value);
            Assert.Equal(Value.Empty, hint[2].Value);
            Assert.Equal(Value.Empty, hint[3].Value);
        }
Ejemplo n.º 4
0
        public void CreateHintBasedOnPlayerSolutionShould_CreateCorrectHintWithAllEmptyValues_BasedOnPlayerSolution()
        {
            var secretSolutionGenerator = new MockSecretSolutionGenerator();
            var mastermind = new Mastermind(secretSolutionGenerator);

            mastermind.SetSecretSolution(_colours);
            var peg1     = new Peg(Colour.Yellow);
            var peg2     = new Peg(Colour.Yellow);
            var peg3     = new Peg(Colour.Yellow);
            var peg4     = new Peg(Colour.Yellow);
            var solution = new[] { peg1, peg2, peg3, peg4 };
            var hint     = mastermind.CreateHintBasedOnPlayerSolution(solution);

            foreach (var item in hint)
            {
                Assert.Equal(Value.Empty, item.Value);
            }
        }
Ejemplo n.º 5
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);
        }