public void Should_terminate_game_after_6_guesses()
        {
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);

            for (int i = 0; i < 5; i++)
            {
                game.Guess("5 2 3 4");
            }

            Assert.True(game.CanContinue);

            game.Guess("5 2 3 4");
            Assert.False(game.CanContinue);
        }
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);

            while (game.CanContinue)
            {
                var input   = Console.ReadLine();
                var message = game.GetMessage(input);
                int count   = 0;
                if (message == "OK")
                {
                    var output = game.Guess(input);
                    count++;
                    Console.WriteLine(output);
                }
                else
                {
                    Console.WriteLine(message);
                }

                if (count == 6)
                {
                    break;
                }
            }

            Console.WriteLine("Game Over");
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);

            while (game.CanContinue)
            {
                var input = Console.ReadLine();
                if (!game.IsInputValid(input))
                {
                    Console.WriteLine("Wrong Input, input again");
                    continue;
                }

                var output = game.Guess(input);
                Console.WriteLine(output);
                if (output == "4A0B")
                {
                    Console.WriteLine("You win");
                    break;
                }

                game.CountInputTimes();
            }

            Console.WriteLine("Game Over");
        }
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);
            int countGameTimes = 0;

            while (game.CanContinue)
            {
                var input = Console.ReadLine();
                if (!game.IsValid(input))
                {
                    continue;
                }

                var output = game.Guess(input);
                Console.WriteLine(output);
                countGameTimes++;
                if (output == "4A0B")
                {
                    Console.WriteLine("You win!");
                    break;
                }

                if (countGameTimes == 6)
                {
                    break;
                }
            }

            Console.WriteLine("Game Over");
        }
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);

            const int maxCount = 6;
            var       count    = 0;

            while (game.CanContinue)
            {
                var input = Console.ReadLine();

                while (!CheckInput(ref input))
                {
                    Console.WriteLine("invalid input");
                    input = Console.ReadLine();
                }

                var output = game.Guess(input);
                Console.WriteLine(output);
                count++;

                if (output == "4A0B" || count == maxCount)
                {
                    break;
                }
            }

            Console.WriteLine("Game Over");
        }
        public void Should_create_0A4B_When_Digital_Right_But_Position_Wrong(string guess)
        {
            var    testSecretGenerator = new TestSecretGernerate();
            var    game   = new BullsAndCowsGame(testSecretGenerator);
            string answer = game.Guess(guess);

            Assert.Equal($"0A4B", answer);
        }
        public void Should_create_0A0B_When_All_Digital_And_Position_Wrong()
        {
            var    testSecretGenerator = new TestSecretGernerate();
            var    game   = new BullsAndCowsGame(testSecretGenerator);
            string answer = game.Guess("5678");

            Assert.Equal($"0A0B", answer);
        }
Ejemplo n.º 8
0
        public void Should_return_wrong_input_tip_when_digits_not_separated_by_space(string guess)
        {
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);

            string answer = game.Guess(guess);

            Assert.Equal("Wrong Input, input again", answer);
        }
        public void Should_create_1A2B_When_Digital_Not_All_Right_And_Position_Are_all_Wrong(string guess, string secret)
        {
            var mockSecretGenerator = new Mock <SecretGenerator>();

            mockSecretGenerator.Setup(mock => mock.GenerateSecret()).Returns(secret);
            //var testSecretGenerator = new TestSecretGernerate();
            var    game   = new BullsAndCowsGame(mockSecretGenerator.Object);
            string answer = game.Guess(guess);

            Assert.Equal($"0A2B", answer);
        }
Ejemplo n.º 10
0
        public void Should_return_0A4B_when_no_digital_right_and__all_positions_wrong()
        {
            //var secretGenerator = new SecretGenerator();
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);
            //when
            string answer = game.Guess("8 7 6 5");

            //then
            Assert.Equal("0A4B", answer);
        }
        public void Should_Return_0A4B_when_all_digit_correct_all_position_wrong(string guess)
        {
            //given
            var testSecretGenerator = new TestSecretGenerator();
            var game = new BullsAndCowsGame(testSecretGenerator);
            //when
            string answer = game.Guess(guess);

            //then
            Assert.Equal("0A4B", answer);
        }
        public void Should_return_0A0B_when_all_wrong()
        {
            //given
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);
            //when
            string answerWithMessage = game.Guess("5 6 7 8");

            //then
            Assert.Equal("0A0B", answerWithMessage.Split(" ")[0]);
        }
Ejemplo n.º 13
0
        public void Should_return_0A0B_when_all_digit_and_position_wrong()
        {
            // given
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);

            // when
            var answer = game.Guess("5 6 7 8");

            // then
            Assert.Equal("0A0B", answer);
        }
Ejemplo n.º 14
0
        public void Should_Guess_return_0A0B_when_all_digit_position_Wrong(string guess)
        {
            // given
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);

            // when
            string answer = game.Guess(guess);

            // then
            Assert.Equal("0A0B", answer);
        }
Ejemplo n.º 15
0
        public void Should_return_1A1B_when_1_digital_right_and__1_positions_wrong(string guess, string secret)
        {
            var mockSecretGenerator = new Mock <SecretGenerator>();

            mockSecretGenerator.Setup(mock => mock.GenerateSecret()).Returns(secret);
            var game = new BullsAndCowsGame(mockSecretGenerator.Object);
            //when
            string answer = game.Guess(guess);

            //then
            Assert.Equal("1A1B", answer);
        }
        public void Should_return_1A2B_given_secret_1234_guess_1425()
        {
            //given
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);
            var expect          = "1A2B";
            //when
            var actual = game.Guess("1 4 2 5");

            //then
            Assert.Equal(expect, actual);
        }
        public void Should_return_0A4B_given_secret_1234_guess_4321_and_3421(string guess)
        {
            //given
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);
            var expect          = "0A4B";
            //when
            var actual = game.Guess(guess);

            //then
            Assert.Equal(expect, actual);
        }
Ejemplo n.º 18
0
        public void Should_return_0A4B_when_digit_wrong_and_position_right(string guess)
        {
            // given
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);

            // when
            var answer = game.Guess(guess);

            // then
            Assert.Equal("0A4B", answer);
        }
Ejemplo n.º 19
0
        public void Should_return_0A0B_when_all_digit_and_position_wrong()
        {
            // given
            var mockSecretGenerator = new Mock <SecretGenerator>();

            mockSecretGenerator.Setup(mock => mock.GenerateSecret()).Returns("1234");
            var game = new BullsAndCowsGame(mockSecretGenerator.Object);
            // when
            string answer = game.Guess("5 6 7 8");

            // then
            Assert.Equal("0A0B", answer);
        }
        public void Should_Return_2A1B_when_digit_partly_correct_position_partly_wrong(string guess, string secrete)
        {
            //given
            var mockSecretGenerator = new Mock <SecretGenerator>();

            mockSecretGenerator.Setup(mock => mock.GenerateSecret()).Returns(secrete);
            var game = new BullsAndCowsGame(mockSecretGenerator.Object);
            //when
            string answer = game.Guess(guess);

            //then
            Assert.Equal("2A1B", answer);
        }
Ejemplo n.º 21
0
        public void Should_return_0A2B_when_two_digit_right_and_no_position_right(string guess, string secret)
        {
            // given
            var mockSecretGenerator = new Mock <SecretGenerator>();

            mockSecretGenerator.Setup(mock => mock.GenerateSecret()).Returns(secret);
            var game = new BullsAndCowsGame(mockSecretGenerator.Object);
            // when
            string answer = game.Guess(guess);

            // then
            Assert.Equal("0A2B", answer);
        }
        public void ShouldReturn4A0BGivenAllDigitAndRightPosition()
        {
            // given
            // var secretGenerator = new SecretGenerator();
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);

            // when
            string answer = game.Guess("1 2 3 4");

            // then
            Assert.Equal("4A0B", answer);
        }
        public void ShouldReturn0A4BGivenAllDigitCorrectAndAllPositionWrong(string guess)
        {
            // given
            // var secretGenerator = new SecretGenerator();
            var secretGenerator = new TestSecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);

            // when
            string answer = game.Guess(guess);

            // then
            Assert.Equal("0A4B", answer);
        }
        public void Should_return_1A2B_for_certain_partially_right_cases(string guess, string secret)
        {
            //given
            var mockSecretGenerator = new Mock <SecretGenerator>();

            mockSecretGenerator.Setup(m => m.GenerateSecret()).Returns(secret);
            var game = new BullsAndCowsGame(mockSecretGenerator.Object);
            //when
            string answerWithMessage = game.Guess(guess);

            //then
            Assert.Equal("1A2B", answerWithMessage.Split(" ")[0]);
        }
        public void Should_return_0A4B_when_all_digits_are_right(string guess, string secret)
        {
            //given
            var mockSecretGenerator = new Mock <SecretGenerator>();

            mockSecretGenerator.Setup(m => m.GenerateSecret()).Returns(secret);
            var game = new BullsAndCowsGame(mockSecretGenerator.Object);
            //when
            string answerWithMessage = game.Guess(guess);

            //then
            Assert.Equal("0A4B", answerWithMessage.Split(" ")[0]);
        }
        public void Should_return_error_message_for_invalid_guess(string guess)
        {
            //given
            var mockSecretGenerator = new Mock <SecretGenerator>();

            mockSecretGenerator.Setup(m => m.GenerateSecret()).Returns("1234");
            var game = new BullsAndCowsGame(mockSecretGenerator.Object);
            //when
            string answer = game.Guess(guess);

            //then
            Assert.Equal("Wrong Input, input again", answer);
        }
Ejemplo n.º 27
0
        public void ShouldReturn1A2BGivenThreeRightDigitAndOneRightPosition(string guess, string secret)
        {
            // given
            var mockSecretGenerator = new Mock <TestSecretGenerator>();

            mockSecretGenerator.Setup(mock => mock.GenerateSecret()).Returns(secret);
            var game = new BullsAndCowsGame(mockSecretGenerator.Object);

            // when
            string answer = game.Guess(guess);

            // then
            Assert.Equal("1A2B", answer);
        }
Ejemplo n.º 28
0
        public void ShouldReturn0A0BGivenDigitNotInSecret(string guess, string secret)
        {
            // given
            var mockSecretGenerator = new Mock <TestSecretGenerator>();

            mockSecretGenerator.Setup(mock => mock.GenerateSecret()).Returns(secret);
            var game = new BullsAndCowsGame(mockSecretGenerator.Object);

            // when
            string answer = game.Guess(guess);

            // then
            Assert.Equal("0A0B", answer);
        }
Ejemplo n.º 29
0
        public void Should_return_4A0B_when_all_digit_and_position_right(string guess, string secret)
        {
            // given
            var fake = new Mock <SecretGenerator>();

            fake.Setup(mock => mock.GenerateSecret()).Returns(secret);
            var game = new BullsAndCowsGame(fake.Object);

            // when
            var answer = game.Guess(guess);

            // then
            Assert.Equal("4A0B", answer);
        }
Ejemplo n.º 30
0
        public void Should_return_1A2B(string guess, string secret)
        {
            // given
            var fake = new Mock <SecretGenerator>();

            fake.Setup(mock => mock.GenerateSecret()).Returns(secret);
            var game = new BullsAndCowsGame(fake.Object);

            // when
            var answer = game.Guess(guess);

            // then
            Assert.Equal("1A2B", answer);
        }