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); } } }
/// <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; } } }