public InstructionConverterShould() { var validator = new InstructionValidator(); _reader = new FileReader(); _sut = new InstructionConverter(validator); }
public Instruction Map(string instructions) { EnsureArg.IsNotNullOrEmpty(instructions, nameof(instructions)); var instruction = new Instruction { InstructionString = instructions }; var instructionValidator = new InstructionValidator(); instructionValidator.ValidateAndThrow(instruction); return(instruction); }
public ICommandResult Handler(DroneCommand command) { //Step 1. Create a new Drone var drone = new Drone(); //Step 2. Validate instruction var instruction = new InstructionValidator(command.Instruction).Instruction; //Step 3. Verify if instruction is valid if (string.IsNullOrEmpty(instruction)) { //Step 4. Invalided the move drone.InvalidMove(); } else { //Step 4. Split instruction in coordinate and values var regex = new Regex(@"[SsNnLlOo]\d*"); var coordinates = regex.Matches(instruction); foreach (var coordinate in coordinates) { //Step 5. Split in name and value var properties = new Regex(@"[SsNnLlOo]|\d+").Matches(coordinate.ToString().Trim()); var nameCoordinate = properties[0].ToString(); var valueCoordinate = properties.Count > 1 ? int.Parse(properties[1].ToString()) : 1; //Step 6. Move the drone drone.Move(new System.Tuple <string, int>(nameCoordinate, valueCoordinate)); } } return(new DroneResult { Drone = drone }); }