public void TestKingMovements()
        {
            string inputCommands = string.Format(
                "kur{0}adr{0}kur{0}bdr{0}kur{0}ddl{0}kur{0}adl{0}kul{0}bdl{0}kur{0}cdl{0}kul",
                Environment.NewLine);

            using (StringWriter stringWriter = new StringWriter())
            {
                Console.SetOut(stringWriter);

                using (StringReader stringReader = new StringReader(inputCommands))
                {
                    Console.SetIn(stringReader);

                    IEngine engine = new ConsoleEngine();
                    engine.Run();

                    char[] separators = Environment.NewLine.ToCharArray();
                    string consoleOutput = stringWriter.ToString();
                    string[] outputLines = consoleOutput.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                    string kingRowActual = outputLines[outputLines.Length - 10];
                    string kingRowExpected = "0 | + - + - + - K - |";

                    Assert.AreEqual<string>(
                        kingRowExpected, kingRowActual, "King not moved correctly!");
                }
            }
        }
        public void TestKingWinsWithInvalidMoves()
        {
            string inputCommands = string.Format(
                "kur{0}bdr{0}kur{0}bdr{0}kul{0}bdr{0}kur{0}{1}kul{0}bdr{0}" +
                "kdr{0}bdr{0}kul{0}bdr{0}{1}bdl{0}kur{0}bdr{0}kul{0}cdr{0}kur",
                Environment.NewLine, 
                Enter);

            using (StringWriter stringWriter = new StringWriter())
            {
                Console.SetOut(stringWriter);

                using (StringReader stringReader = new StringReader(inputCommands))
                {
                    Console.SetIn(stringReader);

                    IEngine engine = new ConsoleEngine();
                    engine.Run();

                    char[] separators = Environment.NewLine.ToCharArray();
                    string consoleOutput = stringWriter.ToString();
                    string[] outputLines = consoleOutput.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                    string expected = "King wins in 9 turns!";
                    int lastLineIndex = outputLines.Length - 1;
                    string actual = outputLines[lastLineIndex];
                    Assert.AreEqual<string>(expected, actual);
                }
            }
        }
        public void TestKingPawn()
        {
            string inputCommands = string.Format(
                "kur{0}adr{0}kur{0}adl{0}kur{0}ddl{0}kur{0}bdr{0}kul{0}bdl{0}kdr{0}bdl{0}kul{0}bdr{0}kur{0}adr{0}kul",
                Environment.NewLine);

            using (StringWriter stringWriter = new StringWriter())
            {
                Console.SetOut(stringWriter);

                using (StringReader stringReader = new StringReader(inputCommands))
                {
                    Console.SetIn(stringReader);

                    IEngine engine = new ConsoleEngine();
                    engine.Run();

                    char[] separators = Environment.NewLine.ToCharArray();
                    string consoleOutput = stringWriter.ToString();
                    string[] outputLines = consoleOutput.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                    string kingInitialRow = outputLines[9];
                    int delimiterFirstIndex = kingInitialRow.IndexOf('|');
                    int delimiterLastIndex = kingInitialRow.LastIndexOf('|');
                    string kingInitialRowInBoard =
                        kingInitialRow.Substring(delimiterFirstIndex + 1, delimiterLastIndex - delimiterFirstIndex - 1);
                    string[] kingInitialRowInBoardSplitted =
                        kingInitialRowInBoard.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    Assert.AreEqual<string>("K", kingInitialRowInBoardSplitted[3]);
                }
            }
        }
Exemplo n.º 4
0
        public static void Main()
        {
            Console.Title = "King Survival v1.0   ---Team Erbium---";

            IEngine consoleEngine = new ConsoleEngine();

            consoleEngine.Run();
        }
        public void TestPawnsMovements()
        {
            string inputCommands = string.Format(
                "kur{0}adr{0}kur{0}adl{0}kur{0}ddl{0}kur{0}bdr{0}kul{0}bdl{0}kdr{0}bdl{0}kul{0}bdr{0}kur{0}adr{0}kul",
                Environment.NewLine);

            using (StringWriter stringWriter = new StringWriter())
            {
                Console.SetOut(stringWriter);

                using (StringReader stringReader = new StringReader(inputCommands))
                {
                    Console.SetIn(stringReader);

                    IEngine engine = new ConsoleEngine();
                    engine.Run();

                    char[] separators = Environment.NewLine.ToCharArray();
                    string consoleOutput = stringWriter.ToString();
                    string[] outputLines = consoleOutput.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                    string pawnARowActual = outputLines[outputLines.Length - 7];
                    string pawnARowExpected = "3 | - A - + - + - + |";

                    string pawnBRowActual = outputLines[outputLines.Length - 6];
                    string pawnBRowExpected = "4 | + - B - + - + - |";

                    string pawnCRowActual = outputLines[outputLines.Length - 10];
                    string pawnCRowExpected = "0 | + - + - C - K - |";

                    string pawnDRowActual = outputLines[outputLines.Length - 9];
                    string pawnDRowExpected = "1 | - + - + - D - + |";

                    Assert.AreEqual<string>(
                        pawnARowExpected, pawnARowActual, "Pawn A not moved correctly!");

                    Assert.AreEqual<string>(
                        pawnBRowExpected, pawnBRowActual, "Pawn B not moved correctly!");

                    Assert.AreEqual<string>(
                        pawnCRowExpected, pawnCRowActual, "Pawn C not moved correctly!");

                    Assert.AreEqual<string>(
                        pawnDRowExpected, pawnDRowActual, "Pawn D not moved correctly!");
                }
            }
        }
        public void TestBoard()
        {
            string inputCommands = string.Format(
                "kul{0}bdr{0}kul{0}bdl{0}kur{0}adr{0}kur{0}bdl{0}kur{0}bdl{0}kul{0}ddl{0}kul",
                Environment.NewLine);

            using (StringWriter stringWriter = new StringWriter())
            {
                Console.SetOut(stringWriter);

                using (StringReader stringReader = new StringReader(inputCommands))
                {
                    Console.SetIn(stringReader);

                    IEngine engine = new ConsoleEngine();
                    engine.Run();

                    char[] separators = Environment.NewLine.ToCharArray();
                    string consoleOutput = stringWriter.ToString();
                    string[] outputLines = consoleOutput.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                    string expected =
                        "    0 1 2 3 4 5 6 7" +
                        "    -----------------" +
                        "0 | A - B - C - D - |" +
                        "1 | - + - + - + - + |" +
                        "2 | + - + - + - + - |" +
                        "3 | - + - + - + - + |" +
                        "4 | + - + - + - + - |" +
                        "5 | - + - + - + - + |" +
                        "6 | + - + - + - + - |" +
                        "7 | - + - K - + - + |" +
                        "   -----------------";
                    int boardInitializationIndex = 11;
                    StringBuilder board = new StringBuilder();
                    for (int i = 0; i < boardInitializationIndex; i++)
                    {
                        board.Append(outputLines[i]);
                    }

                    string actual = board.ToString();
                    Assert.AreEqual<string>(expected, actual, "Board is not create correctly!");
                }
            }
        }
        public void TestKingIsTrappedInRightDownCorner()
        {
            string inputCommands = string.Format(
                "kur{0}bdl{0}kur{0}bdr{0}kul{0}bdr{0}kdr{0}bdr{0}kdr{0}bdr{0}kdr{0}bdr",
                Environment.NewLine);

            using (StringWriter stringWriter = new StringWriter())
            {
                Console.SetOut(stringWriter);

                using (StringReader stringReader = new StringReader(inputCommands))
                {
                    Console.SetIn(stringReader);

                    IEngine engine = new ConsoleEngine();
                    engine.Run();

                    char[] separators = Environment.NewLine.ToCharArray();
                    string consoleOutput = stringWriter.ToString();
                    string[] outputLines = consoleOutput.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                    string expected = "King loses in 6 turns...";
                    int lastLineIndex = outputLines.Length - 1;
                    string actual = outputLines[lastLineIndex];
                    Assert.AreEqual<string>(expected, actual);
                }
            }
        }