Exemple #1
0
        public void Dron_Move()
        {
            var arrMove = new[]
            {
                "R", "r", "L", "l", "asd", "RT", "2", "MmmmmM"
            };

            var dron = new RobotBody(new Point(1, 1), new Course("N"));

            var area = new Area(new Point(1, 1));

            foreach (var element in arrMove)
            {
                try
                {
                    dron.Run(new Command(element), area);
                }
                catch (CommandException exceptionCommand)
                {
                    Assert.AreEqual("Ваша команда не корректна", exceptionCommand.Message);
                }
                catch (MoveException exceptionMove)
                {
                    Assert.AreEqual("Дрон выходит из зданного поля", exceptionMove.Message);
                }
            }
        }
Exemple #2
0
        public void Area_Constructor_X_Y_int()
        {
            var values = new[]
            {
                -1, 1, 2, 3, -1, 400000000
            };

            foreach (var xElement in values)
            {
                try
                {
                    var area = new Area(new Point(xElement, 1)); //xElement, 1);

                    var actual = area.Point.X;

                    Assert.AreEqual(xElement, actual);
                }
                catch (PointException exceptionPoint)
                {
                    Assert.AreEqual("Задать X координату можно от 0 до 2147483647", exceptionPoint.Message);
                }

            }

            foreach (var yElement in values)
            {
                try
                {
                    var area = new Area(new Point(1, yElement));//(1, yElement);

                    var actual = area.Point.Y;

                    Assert.AreEqual(yElement, actual);
                }
                catch (PointException exceptionPoint)
                {
                    Assert.AreEqual("Задать Y координату можно от 0 до 2147483647", exceptionPoint.Message);
                }

            }
        }
Exemple #3
0
        /// <summary>
        /// Распредиление команд по объектам
        /// </summary>
        /// <param name="devideCommand">Класс для дробления сырого текста команд на массив для дальнейшего распределения по объектам</param>
        public ControlCommand(DevideCommand devideCommand)
        {
            GetFinalPositionRobot = new Dictionary<string, string>();

            Area area = new Area(new Point(devideCommand.GetArrayListCommand[0]));

            List<RobotBody> dronsList = new List<RobotBody>();

            int j = 1;
            int i = 0;

            while (i < ((devideCommand.GetArrayListCommand.Length - 1) / 2))
            {
                Regex regex = new Regex(@"^\s*\d+\s+\d+\s+[NnEeSsWw]$");
                if (regex.IsMatch(devideCommand.GetArrayListCommand[j]))
                {
                    regex = new Regex(@"(\d+\s+\d+)|([NnEeSsWw])");
                    MatchCollection matches = regex.Matches(devideCommand.GetArrayListCommand[j]);
                    RobotBody dron = new RobotBody(
                        new Point(matches[0].Value),
                        new Course(matches[1].ToString())
                        );

                    j++;
                    dron.Run(new Command(devideCommand.GetArrayListCommand[j]), area);
                    dronsList.Add(dron);
                    j++;
                    i++;
                    GetFinalPositionRobot.Add("Робот № " + i, String.Format("{0} {1} {2}\r\n", dron.Point.X, dron.Point.Y, dron.Course.Direction));
                }
                else
                {
                    CommandControlException ex = new CommandControlException("Строка не корректна.");
                    ex.Data.Add("Возможная ошибка в строке", devideCommand.GetArrayListCommand[j]);
                    throw ex;
                }
            }
        }
Exemple #4
0
        public void Area_Constructor_X_Y_string()
        {
            var inputStringXY = new[]
            {
                "      0000020000103       0150       ",
                "1 -1",
                "-1 1",
                "05 06",
                "1 1",
                "0304 430",
                "10 01",
                "      103       015       "
            };
            var outputValues = new[]
            {
                20000103, 150,
                1, -1,
                -1, 1,
                5, 6,
                1, 1,
                304, 430,
                10, 01,
                103, 15
            };

            for (int i = 0; i < inputStringXY.Length; i++)
            {
                try
                {
                    var area = new Area(new Point(inputStringXY[i]));//arrIn[i]);

                    var actual = area.Point.X;
                    Assert.AreEqual(outputValues[i * 2], actual);

                    actual = area.Point.Y;
                    Assert.AreEqual(outputValues[i * 2 + 1], actual);
                }
                catch (PointException exceptionPoint)
                {
                    Assert.AreEqual("Строка должна содержать 2 числа через [Пробел]. Только положительные числа.", exceptionPoint.Message);
                }
            }
        }
Exemple #5
0
 /// <summary>
 /// Движение робота
 /// </summary>
 /// <param name="command"></param>
 /// <param name="area"></param>
 public void Run(Command command, Area area)
 {
     new Move(Point, Course, command, area);
 }