Beispiel #1
0
        public void Should_return_1_RoverCommand()
        {
            //Given
            var commandStrings = new List <string> {
                "5 5", "1 1 N", "MM"
            };
            //When
            var roverCommands = ParseRobotCommands.From(commandStrings);

            //Then
            Assert.That(roverCommands.Count(), Is.EqualTo(1), "Should parser only 1 RoverCommand");

            var robotCommand = roverCommands.First();

            Assert.That(robotCommand.StartingPosition, Is.EqualTo(ParsePosition.From("1 1 N")));
        }
Beispiel #2
0
        public void SendCommand(IEnumerable <string> input)
        {
            if (!input.Any())
            {
                throw new InvalidCommandException("Please provide valid command and position.");
            }

            var rovers        = new List <Robot>();
            var roverCommands = ParseRobotCommands.From(input);

            foreach (var roverCommand in roverCommands)
            {
                var robot = new Robot(roverCommand.StartingPosition, _output);
                foreach (var instruction in roverCommand.Instructions)
                {
                    robot.Send(instruction);
                }

                rovers.Add(robot);
                _output.Write(robot.CurrentPosition.ToString());
            }
        }