示例#1
0
        public void TestUserInputMinesNumberWithOne()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (StringReader sr = new StringReader(string.Format("1{0}", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    GameBoardGenerator.GetBoardSize();
                    Assert.IsTrue(GameBoardGenerator.MinesNumber >= 1);
                }
            }
        }
示例#2
0
        public void TestUserInputCorrectFieldSize()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (StringReader sr = new StringReader(string.Format("5{0}", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    GameBoardGenerator.GetBoardSize();
                    Assert.AreEqual(GameBoardGenerator.GameField.Length, 25);
                }
            }
        }
        public void TestUserInputCorrectCoordinates()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (StringReader sr = new StringReader(string.Format("10{0}5 5{0}", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    GameBoardGenerator.GetBoardSize();
                    GameInput.ManageUserInput(GameBoardGenerator.GameField);
                    Assert.IsTrue(GameInput.ColCoordinate == 5 && GameInput.RowCoordinate == 5);
                }
            }
        }
示例#4
0
        public void TestUserInputWithOutOfRangeParameters()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (StringReader sr = new StringReader(string.Format("11{0}2{0}", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    GameBoardGenerator.GetBoardSize();
                    string expectedResult = "Welcome to \"Battle Field\" game.\r\nEnter battle field size between 1 and 10: Size must be between 1 and 10 \nInput new size:";
                    Assert.AreEqual <string>(expectedResult, sw.ToString());
                }
            }
        }
        public void TestBigFieldExplosion()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (StringReader sr = new StringReader(string.Format("10{0}", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    GameBoardGenerator.GetBoardSize();
                    int result = MinesExplosion.CheckForExplosion(GameBoardGenerator.GameField, 5, 5);
                    Assert.IsTrue(result >= 2);
                }
            }
        }
示例#6
0
        public void TestCorrectPrintedFieldSizeWithOne()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (StringReader sr = new StringReader(string.Format("1{0}", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    GameBoardGenerator.GetBoardSize();
                    PrintGameBoard.PrintField(GameBoardGenerator.GameField);
                    string result = sw.ToString();
                    Assert.IsTrue(result.Length == 92);
                }
            }
        }
示例#7
0
        public void TestCorrectPrintedFieldSizeWithSix()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (StringReader sr = new StringReader(string.Format("6{0}", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    GameBoardGenerator.GetBoardSize();
                    PrintGameBoard.PrintField(GameBoardGenerator.GameField);
                    string result = sw.ToString();
                    Assert.IsTrue(result.Length == 202);//size of printed array without the string length of the GetBoardSize console writings
                }
            }
        }
        public void TestUserInputIncorrectFormatLength2()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (StringReader sr = new StringReader(string.Format("8{0}ss{0}4 4{0}", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    GameBoardGenerator.GetBoardSize();
                    GameInput.ManageUserInput(GameBoardGenerator.GameField);
                    string output         = sw.ToString();
                    string expectedresult = "Welcome to \"Battle Field\" game.\r\nEnter battle field size between 1 and 10: Please enter coordinates: Choose x and y coordinates, seperated by white space in correct format [Example:2 5]\r\nPlease enter coordinates: ";
                    Assert.AreEqual(expectedresult.Length, output.Length);
                }
            }
        }
        public void TestUserInputOutsideOfField()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (StringReader sr = new StringReader(string.Format("8{0}9 9{0}3 3{0}", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    GameBoardGenerator.GetBoardSize();
                    GameInput.ManageUserInput(GameBoardGenerator.GameField);
                    string output         = sw.ToString();
                    string expectedresult = "Welcome to \"Battle Field\" game. \nEnter battle field size between 1 and 10: Please enter coordinates: Outside of Field Range  Please enter coordinates: ";
                    Assert.AreEqual(expectedresult.Length, output.Length);
                }
            }
        }