public void Example3()
        {
            var sol = new BullsAndCows();

            Assert.AreEqual("1A0B", sol.GetHint("1234", "1111"));

            Assert.AreEqual("1A0B", sol.GetHint("4321", "2222"));
        }
Ejemplo n.º 2
0
        public void ProccessGues_Secret1234Guess1234_ShouldNeverReturn3Bull1Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 1, 2, 3, 4 };
            string guess = "1234";

            // Act
            game.ProccessGues(secret, guess, out bulls, out cows);

            // Assert
            Assert.IsFalse(cows == 3 && bulls == 1);
        }
        public void CalculateBullsAndCows_ifGuessLengthIsSmallerThanNUMBER_OF_DIGITS_ShouldReturnFalse()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 1, 1, 1, 1 };
            string guess = GetRandomNumberAsString(BullsAndCows.NUMBER_OF_DIGITS - 1);

            // Act
            bool isValidGuess = game.CalculateBullsAndCows(secret, guess, out bulls, out cows);

            // Assert
            Assert.IsFalse(isValidGuess);
        }
Ejemplo n.º 4
0
        public void ProccessGues_Secret1234Guess1243_2Bull2Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 1, 2, 3, 4 };
            string guess = "1243";

            // Act
            game.ProccessGues(secret, guess, out bulls, out cows);

            // Assert
            Assert.IsTrue(cows == 2 && bulls == 2);
        }
        public void CalculateBullsAndCows_ifGuessLengthEqualsToNUMBER_OF_DIGITSAndGuessNumberParseSucceed_ShouldReturnTrue()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 1, 1, 1, 1 };
            string guess = GetRandomNumberAsString(BullsAndCows.NUMBER_OF_DIGITS);

            // Act
            bool isValidGuess = game.CalculateBullsAndCows(secret, guess, out bulls, out cows);

            // Assert
            Assert.IsTrue(isValidGuess);
        }
Ejemplo n.º 6
0
        public void TestMainMethod()
        {
            var outputWriter = new StringWriter();

            Console.SetOut(outputWriter);

            var input       = "exit";
            var inputReader = new StringReader(input);

            Console.SetIn(inputReader);

            BullsAndCows.Main();

            var output         = outputWriter.ToString();
            var expectedOutput = "Welcome to “Bulls and Cows” game. Please try to guess my secret 4-digit number.\n" +
                                 "Use 'top' to view the top scoreboard, 'restart' to start a new game and 'help' to cheat and 'exit' to quit the game.\n" +
                                 "Enter your guess or command: " +
                                 "Good Bye!\n";

            Assert.AreEqual(output, expectedOutput, "Invalid start message.\n");
        }
Ejemplo n.º 7
0
        public void ProccessGues_Secret5694Guess5555_1Bull0Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 5, 6, 9, 4 };
            string guess = "5555";

            // Act
            game.ProccessGues(secret, guess, out bulls, out cows);

            // Assert
            Assert.IsTrue(cows == 0 && bulls == 1);
        }
Ejemplo n.º 8
0
        public void ProccessGues_Secret2424Guess4144_1Bull1Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 2, 4, 2, 4 };
            string guess = "4144";

            // Act
            game.ProccessGues(secret, guess, out bulls, out cows);

            // Assert
            Assert.IsTrue(cows == 1 && bulls == 1);
        }
Ejemplo n.º 9
0
        public void ProccessGues_Secret1234Guess5678_0Bull0Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 1, 2, 3, 4 };
            string guess = "5678";

            // Act
            game.ProccessGues(secret, guess, out bulls, out cows);

            // Assert
            Assert.IsTrue(cows == 0 && bulls == 0);
        }
Ejemplo n.º 10
0
    public static void Main()
    {
        BullsAndCows game = new BullsAndCows();

        game.StartGame();
    }
Ejemplo n.º 11
0
 public static void Main()
 {
     BullsAndCows game = new BullsAndCows();
     game.StartGame();
 }
        public void CalculateBullsAndCows_Secret0987Guess0987_ShouldNeverReturn3Bull1Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 0, 9, 8, 7 };
            string guess = "0987";

            // Act
            game.CalculateBullsAndCows(secret, guess, out bulls, out cows);

            // Assert
            Assert.IsFalse(bulls == 3 && cows == 1);
        }
        public void Example1()
        {
            var sol = new BullsAndCows();

            Assert.AreEqual("1A3B", sol.GetHint("1807", "7810"));
        }
        public void CalculateBullsAndCows_Secret4440Guess1234_0Bull1Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 4, 4, 4, 0 };
            string guess = "1234";

            // Act
            game.CalculateBullsAndCows(secret, guess, out bulls, out cows);

            // Assert
            Assert.AreEqual(0, bulls);
            Assert.AreEqual(1, cows);
        }
        public void CalculateBullsAndCows_Secret2424Guess4144_1Bull1Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 2, 4, 2, 4 };
            string guess = "4144";

            // Act
            game.CalculateBullsAndCows(secret, guess, out bulls, out cows);

            // Assert
            Assert.AreEqual(1, bulls);
            Assert.AreEqual(1, cows);
        }
        public void CalculateBullsAndCows_Secret1234Guess5678_0Bull0Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 1, 2, 3, 4 };
            string guess = "5678";

            // Act
            game.CalculateBullsAndCows(secret, guess, out bulls, out cows);

            // Assert
            Assert.AreEqual(0, bulls);
            Assert.AreEqual(0, cows);
        }
        public void CalculateBullsAndCows_Secret1234Guess1923_1Bull2Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 1, 2, 3, 4 };
            string guess = "1923";

            // Act
            game.CalculateBullsAndCows(secret, guess, out bulls, out cows);

            // Assert
            Assert.AreEqual(1, bulls);
            Assert.AreEqual(2, cows);
        }
Ejemplo n.º 18
0
        public void ShouldBeEqual_ifGuessLengthHasExpectedLength()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 1, 1, 1, 1 };
            string guess = "1234";

            // Act
            bool isValidGuess = game.ProccessGues(secret, guess, out bulls, out cows);

            // Assert
            Assert.AreEqual(guess.Length == BullsAndCows.NUMBER_OF_DIGITS, isValidGuess);
        }
        public void CalculateBullsAndCows_IfGuessNumberParseFails_ShouldReturnFalse()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 1, 1, 1, 1 };
            string[] guesses = { "G123", "1G34", "12G4", "123G" };

            for (int i = 0; i < guesses.Length; i++)
            {
                string guess = guesses[i];
                bool isValidGuess = game.CalculateBullsAndCows(secret, guess, out bulls, out cows);
                Assert.IsFalse(isValidGuess);
            }
        }
        public void CalculateBullsAndCows_Secret5694Guess5555_1Bull0Cow()
        {
            // Arrange
            BullsAndCows game = new BullsAndCows();
            int bulls = 0;
            int cows = 0;
            int[] secret = { 5, 6, 9, 4 };
            string guess = "5555";

            // Act
            game.CalculateBullsAndCows(secret, guess, out bulls, out cows);

            // Assert
            Assert.AreEqual(1, bulls);
            Assert.AreEqual(0, cows);
        }
 public void BeforeEach()
 {
     BullsAndCows = new BullsAndCows();
 }
        public void GetScoreBoardAsStringMethod_IfScoreBoardIsSortedCorrectly()
        {
            // Prepair input
            var input = new StringBuilder();
            int peshoAttempts = 1;
            input.AppendLine("2222");
            input.AppendLine("Pesho");
            int goshoAttempts = 3;
            input.AppendLine("2223");
            input.AppendLine("2223");
            input.AppendLine("2222");
            input.AppendLine("Gosho");
            int miroslavAttempts = 2;
            input.AppendLine("2223");
            input.AppendLine("2222");
            input.AppendLine("Miroslav");
            //input.AppendLine("top");
            input.AppendLine("exit");

            // Prepair expected
            var expectedOutput = new StringBuilder();
            expectedOutput.AppendLine(BullsAndCows.START_EXPRESSION);
            expectedOutput.AppendLine(BullsAndCows.ENTER_GUESS);
            expectedOutput.AppendLine(String.Format(BullsAndCows.CONGRATULATIONS_WITHOUT_CHEATS, peshoAttempts));
            expectedOutput.AppendLine(BullsAndCows.ASK_NAME_FOR_SCOREBOARD);
            expectedOutput.AppendLine(ScoreBoard.SCOREBOARD_TITLE);
            expectedOutput.AppendLine(String.Format(ScoreBoard.SCOREBOARD_INPUT_FORMAT, 1, "Pesho", peshoAttempts));
            expectedOutput.AppendLine();

            expectedOutput.AppendLine(BullsAndCows.START_EXPRESSION);
            expectedOutput.AppendLine(BullsAndCows.ENTER_GUESS);
            expectedOutput.AppendLine("Wrong number!  Bulls: 3, Cows: 0");
            expectedOutput.AppendLine(BullsAndCows.ENTER_GUESS);
            expectedOutput.AppendLine("Wrong number!  Bulls: 3, Cows: 0");
            expectedOutput.AppendLine(BullsAndCows.ENTER_GUESS);
            expectedOutput.AppendLine(String.Format(BullsAndCows.CONGRATULATIONS_WITHOUT_CHEATS, goshoAttempts));
            expectedOutput.AppendLine(BullsAndCows.ASK_NAME_FOR_SCOREBOARD);
            expectedOutput.AppendLine(ScoreBoard.SCOREBOARD_TITLE);
            expectedOutput.AppendLine(String.Format(ScoreBoard.SCOREBOARD_INPUT_FORMAT, 1, "Pesho", peshoAttempts));
            expectedOutput.AppendLine(String.Format(ScoreBoard.SCOREBOARD_INPUT_FORMAT, 2, "Gosho", goshoAttempts));
            expectedOutput.AppendLine();

            expectedOutput.AppendLine(BullsAndCows.START_EXPRESSION);
            expectedOutput.AppendLine(BullsAndCows.ENTER_GUESS);
            expectedOutput.AppendLine("Wrong number!  Bulls: 3, Cows: 0");
            expectedOutput.AppendLine(BullsAndCows.ENTER_GUESS);
            expectedOutput.AppendLine(String.Format(BullsAndCows.CONGRATULATIONS_WITHOUT_CHEATS, miroslavAttempts));
            expectedOutput.AppendLine(BullsAndCows.ASK_NAME_FOR_SCOREBOARD);
            expectedOutput.AppendLine(ScoreBoard.SCOREBOARD_TITLE);
            expectedOutput.AppendLine(String.Format(ScoreBoard.SCOREBOARD_INPUT_FORMAT, 1, "Pesho", peshoAttempts));
            expectedOutput.AppendLine(String.Format(ScoreBoard.SCOREBOARD_INPUT_FORMAT, 2, "Miroslav", miroslavAttempts));
            expectedOutput.AppendLine(String.Format(ScoreBoard.SCOREBOARD_INPUT_FORMAT, 3, "Gosho", goshoAttempts));
            expectedOutput.AppendLine();

            expectedOutput.AppendLine(BullsAndCows.START_EXPRESSION);
            expectedOutput.AppendLine(BullsAndCows.ENTER_GUESS);
            expectedOutput.AppendLine(BullsAndCows.EXIT_GAME);
            // Redirect Console
            Console.SetIn(new StringReader(input.ToString()));
            StringWriter consoleOutput = new StringWriter();
            Console.SetOut(consoleOutput);

            // mock
            var mockedNumber = Mock.Create<IRandomNumberProvider>();
            Mock.Arrange(() => mockedNumber.GetRandomNumber(0, 10)).Returns(2);
            BullsAndCows game = new BullsAndCows(mockedNumber);
            game.StartGame();

            string expected = expectedOutput.ToString();
            string actual = consoleOutput.ToString();
            Assert.AreEqual(expected, actual);
        }
        public void Example2()
        {
            var sol = new BullsAndCows();

            Assert.AreEqual("1A1B", sol.GetHint("1123", "0111"));
        }