private Tuple <int, int> GetPotentialPosition(ToyRobot toyRobot) { Tuple <int, int, FacesEnum> currentPosition = toyRobot.GetCurrentPosition(); switch (currentPosition.Item3) { case FacesEnum.NORTH: return(Tuple.Create(currentPosition.Item1, currentPosition.Item2 + unitsToMove)); case FacesEnum.SOUTH: return(Tuple.Create(currentPosition.Item1, currentPosition.Item2 - unitsToMove)); case FacesEnum.WEST: return(Tuple.Create(currentPosition.Item1 - unitsToMove, currentPosition.Item2)); case FacesEnum.EAST: return(Tuple.Create(currentPosition.Item1 + unitsToMove, currentPosition.Item2)); default: throw new InvalidToyRobotFaceException(); } }
public void PlaceRobotInMap() { /* * Should test each of the cases where a robot can be placed in a map * 1. Test initial state * 2. Out of bounds * 3. Between (0,0) and (4,4) */ //1 Assert.Throws <ToyRobotHasNotBeenPlacedException>(() => toyRobot.GetCurrentPosition()); Assert.IsFalse(toyRobot.HasBeenPlaced()); //2 var args = "-1,0,WEST"; PlaceCommand placeCommand = new PlaceCommand(map, args); Assert.Throws <InvalidPlaceCommandException>(() => toyRobot.Execute(placeCommand)); //2.1 args = "2,5,WEST"; placeCommand = new PlaceCommand(map, args); Assert.Throws <InvalidPlaceCommandException>(() => toyRobot.Execute(placeCommand)); //3 args = "0,0,NORTH"; placeCommand = new PlaceCommand(map, args); toyRobot.Execute(placeCommand); //3.1 args = "3,4,NORTH"; placeCommand = new PlaceCommand(map, args); toyRobot.Execute(placeCommand); }
private FacesEnum GetPotentialFace(ToyRobot toyRobot) { Tuple <int, int, FacesEnum> currentPosition = toyRobot.GetCurrentPosition(); return(Faces.TurnLeft(currentPosition.Item3)); }
void ICommand.Execute(ToyRobot toyRobot) { Tuple <int, int, FacesEnum> position = toyRobot.GetCurrentPosition(); Console.WriteLine(position.Item1 + "," + position.Item2 + "," + position.Item3); }