public void Execute(Robot robot, string parameters) { var inputs = parameters.Split(","); if (inputs.Length != 3) { throw new ArgumentException("Expected X,Y,F"); } int x, y; if (!Int32.TryParse(inputs[0], out x)) { throw new ArgumentException("Invalid X parameter for PLACE"); } if (!Int32.TryParse(inputs[1], out y)) { throw new ArgumentException("Invalid Y parameter for PLACE"); } if (!Bearing.IsValidBearing(inputs[2])) { throw new ArgumentException("Invalid F parameter for PLACE"); } robot.SetPosition(x, y); robot.SetBearing(inputs[2]); }
public bool CanExecute(Robot robot) { // Need a valid current position and bearing to move return(robot.xPos != null && robot.yPos != null && Bearing.IsValidBearing(robot.bearing)); }
public void TestIsValidBearingTrue() { Assert.IsTrue(Bearing.IsValidBearing("NORTH")); }
public void TestIsValidBearingFalse() { Assert.IsFalse(Bearing.IsValidBearing("SPAM")); }
public bool CanExecute(Robot robot) { // Need a valid current bearing to turn return(Bearing.IsValidBearing(robot.bearing)); }