public void IntegrationTest() { var surface = _marsSurfaceFactory.Create(new Vector2(5, 3)); var firstRobot = _martianRobotFactory.Create(surface, new Vector2(1, 1), Direction.East); var secondRobot = _martianRobotFactory.Create(surface, new Vector2(3, 2), Direction.North); var thirdRobot = _martianRobotFactory.Create(surface, new Vector2(0, 3), Direction.West); _firstRobotCommands.ForEach(a => firstRobot.Move(a)); _secondRobotCommands.ForEach(a => secondRobot.Move(a)); _thirdRobotCommands.ForEach(a => thirdRobot.Move(a)); Assert.AreEqual(new Vector2(1, 1), firstRobot.Position); Assert.AreEqual(Direction.East, firstRobot.Direction); Assert.AreEqual(MarsRobotState.Active, firstRobot.State); Assert.AreEqual(new Vector2(3, 3), secondRobot.Position); Assert.AreEqual(Direction.North, secondRobot.Direction); Assert.AreEqual(MarsRobotState.Lost, secondRobot.State); Assert.AreEqual(new Vector2(2, 3), thirdRobot.Position); Assert.AreEqual(Direction.South, thirdRobot.Direction); Assert.AreEqual(MarsRobotState.Active, thirdRobot.State); }
public void Run() { try { var applicationInput = ReadApplicationInput(); var surface = _marsSurfaceFactory.Create(applicationInput.SurfaceDimension); foreach (var robotInput in applicationInput.Robots) { var robot = _martianRobotFactory.Create( surface, robotInput.StartPosition, robotInput.Direction); robotInput.Commands.ForEach(c => robot.Move(c)); Console.WriteLine($"{robot.Position.X} {robot.Position.Y} " + $"{robot.Direction.ToOutput()} " + $"{(robot.State == MarsRobotState.Lost ? "LOST" : null)}"); } } catch (InvalidDataException) { Console.WriteLine("Error in input data format. Try again."); Run(); } catch (Exception e) { Console.WriteLine(e); Console.WriteLine("Unexpected error. Try again."); Run(); } }