public bool TryReadInput(string input, out IWorld world, out IEnumerable <IRobot> robots) { try { if (string.IsNullOrEmpty(input)) { throw new ArgumentException("Input settings cannot be empty", nameof(input)); } var inputLines = input.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); var inputQueue = new Queue <string>(inputLines); var worldSize = ReadWorldSize(inputQueue.Dequeue()); robots = ReadRobotSettings(inputQueue); world = new MartianWorld(worldSize.Width, worldSize.Height); return(true); } catch (Exception e) { world = null; robots = null; Console.WriteLine(e.Message); return(false); } }
public void TestRobotMoveCommand() { var world = new MartianWorld(3, 3); var rotateLeft = new ForwardCommand(world); var robot = new Robot(new Point(0, 0), RobotOrientation.North); rotateLeft.ExecuteCommandFor(robot); Assert.AreEqual(robot.Coordinates, new Point(0, 1)); }
public void TestCommandExecutor() { var world = new MartianWorld(2, 2); var shouldDieRobot = new Robot(new Point(0, 0), RobotOrientation.South); var shouldMoveRobot = new Robot(new Point(0, 0), RobotOrientation.North); var commandExecutor = new CommandExecutor(world); shouldDieRobot.SetOrders("F"); shouldMoveRobot.SetOrders("F"); commandExecutor.ExecuteNextCommand(shouldDieRobot); commandExecutor.ExecuteNextCommand(shouldMoveRobot); Assert.False(shouldDieRobot.Alive); Assert.True(shouldMoveRobot.Alive); Assert.AreEqual(shouldMoveRobot.Coordinates, new Point(0, 1)); }