Exemplo n.º 1
0
        public void Dron_Direction()
        {
            var arrDirectionStart = new[]
            {
                "N", "n", "E", "e", "W", "w", "S", "s", "tT"
            };

            var arrDirectionFinish = new[]
            {
                "N", "N", "E", "E", "W", "W", "S", "S", "ERROR"
            };

            for (int i = 0; i < arrDirectionStart.Length; i++)
            {
                try
                {
                    var dron = new RobotBody(new Point(1, 1), new Course(arrDirectionStart[i]));

                    var actual = dron.Course.Direction;

                    Assert.AreEqual(arrDirectionFinish[i], actual);
                }
                catch (CourseException exceptionCourse)
                {
                    Assert.AreEqual("Направление может быть одно из (N, E, S, W)", exceptionCourse.Message);
                }
            }
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 4
0
        public void Dron_X()
        {
            var arrX = new[]
            {
                1, 2, 3, -2
            };

            foreach (var element in arrX)
            {
                try
                {
                    var dron = new RobotBody(new Point(element, 1), new Course("N"));

                    var actual = dron.Point.X;

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

            }
        }