public void FacingWest() { Rover rover = new Rover(new Position(1, 1), RoverFacing.West, playGround); rover.TurnLeft(); RoverFacing roverfacing = rover.Facing; Assert.AreEqual(RoverFacing.South, roverfacing); }
public void FacingEast() { Rover rover = new Rover(new Position(2, 0), RoverFacing.East, playGround); rover.TurnLeft(); RoverFacing roverfacing = rover.Facing; Assert.AreEqual(RoverFacing.North, roverfacing); }
public void FacingSouth() { Rover rover = new Rover(new Position(0, 2), RoverFacing.South, playGround); rover.TurnLeft(); RoverFacing roverfacing = rover.Facing; Assert.AreEqual(RoverFacing.East, roverfacing); }
public void FacingWest() { Rover rover = new Rover(new Position(0, 0), RoverFacing.West, playGround); rover.TurnRight(); RoverFacing roverfacing = rover.Facing; Assert.AreEqual(RoverFacing.North, roverfacing); }
public Rover(Position position, RoverFacing facing, PlayGround playGround) { Position = position; Facing = facing; this.playGround = playGround; if (!IsPositionGood(position)) { throw new ArgumentException("initial position outside border"); } }
public void FacingNorth() { // arrange Rover rover = new Rover(new Position(1, 1), RoverFacing.North, playGround); // act rover.TurnLeft(); // assert RoverFacing roverfacing = rover.Facing; // (first expected than actual) Assert.AreEqual(RoverFacing.West, roverfacing); }
public override int GetHashCode() { var hashCode = 1494645696; hashCode = hashCode * -1521134295 + RoverFacing.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <Position> .Default.GetHashCode(RoverPosition); hashCode = hashCode * -1521134295 + EqualityComparer <Dictionary <string, ICommand> > .Default.GetHashCode(Commands); return(hashCode); }
public void Should_change_facing_to_north_rotate_to_right() { // GIVEN var facing = new RoverFacing(FacingTypes.West); // WHEN facing.MoveToRight(); // THEN Assert.IsNotNull(facing); Assert.AreEqual(FacingTypes.North, facing.CurrentFacing); }
public void Should_change_facing_to_west_when_rotate_to_left() { // GIVEN var facing = new RoverFacing(FacingTypes.North); // WHEN facing.MoveToLeft(); // THEN Assert.IsNotNull(facing); Assert.AreEqual(FacingTypes.West, facing.CurrentFacing); }
public void Execute_Exit_command(string commands, RoverFacing expectedRoverFacing, int expectedRoverPositionX, int expectedRroverPositionY) { var expectedConsoleOut = string.Empty; int consoleExitCode; using (var consoleOutput = new ConsoleOutput()) { consoleExitCode = StartConsoleApplication(commands); Assert.AreEqual(0, consoleExitCode); Assert.AreEqual(expectedConsoleOut, consoleOutput.GetOuput().Replace("\r", string.Empty).Replace("\n", string.Empty)); } }
public void ChangeFacing(bool left) { if (left) { roverFacing = roverFacing == RoverFacing.North ? RoverFacing.West : (RoverFacing)((int)roverFacing - 1); } else { roverFacing = roverFacing == RoverFacing.West ? RoverFacing.North : (RoverFacing)((int)roverFacing + 1); } Console.WriteLine($"Rover is now at {roverPositionX}, {roverPositionY} - facing {roverFacing}"); }
public void Execute_command_north_forward(string commands, RoverFacing expectedRoverFacing, int expectedRoverPositionX, int expectedRroverPositionY) { // Arrange var expectedRover = new Rover(expectedRoverFacing, new Position(expectedRoverPositionX, expectedRroverPositionY)); var rover = _rover; // Act foreach (var command in commands.ToCharArray()) { rover.Execute(command.ToString()); } // Assert Assert.AreEqual(expectedRover, _rover); }
public void Rotate_left_test(int index, RoverFacing roverFacing) { // Arrange var expectedRoverFacing = roverFacing; var rover = _rover; // Act for (var i = 0; i < index; i++) { rover.RotateLeft(); } // Assert Assert.AreEqual(rover.RoverFacing, expectedRoverFacing); }
public void Rotate_left_command_test(int index, RoverFacing roverFacing) { // Arrange var expectedRoverFacing = roverFacing; var rover = _rover; var rotateRoverLeftCommand = new RotateRoverLeftCommand(rover); // Act for (var i = 0; i < index; i++) { rotateRoverLeftCommand.Execute(); } // Assert Assert.AreEqual(rover.RoverFacing, expectedRoverFacing); }
public void Execute_rotate_rover_right_command_test(string commands, RoverFacing expectedRoverFacing, int expectedRoverPositionX, int expectedRroverPositionY) { // Arrange var expectedRover = new Rover(expectedRoverFacing, new Position(expectedRoverPositionX, expectedRroverPositionY)); var rover = _rover; // Act foreach (var command in commands.ToCharArray()) { rover.Execute(command.ToString()); } // Assert Assert.AreEqual(expectedRover.RoverPosition, _rover.RoverPosition); Assert.AreEqual(expectedRover.RoverFacing, _rover.RoverFacing); Assert.IsInstanceOfType(expectedRover.Commands["R"], _rover.Commands["R"].GetType()); Assert.IsInstanceOfType(expectedRover.Commands["L"], _rover.Commands["L"].GetType()); Assert.IsInstanceOfType(expectedRover.Commands["F"], _rover.Commands["F"].GetType()); }
public static void PrintRoverPosition(int roverPositionX, int roverPositionY, RoverFacing roverFacing) { Console.WriteLine($"Rover is now at {roverPositionX}, {roverPositionY} - facing {roverFacing}\r\n"); }
private RoverPosition() { RoverPositionX = 0; RoverPositionY = 0; RoverFacingPosition = RoverFacing.North; }
public void TurnRight() { Facing = Facing == RoverFacing.West ? RoverFacing.North : (RoverFacing)((int)Facing + 1); }
public void TurnLeft() { Facing = Facing == RoverFacing.North ? RoverFacing.West : (RoverFacing)((int)Facing - 1); }
internal RoverStatus(MapCoordinates position, RoverFacing facing) { Position = position; Facing = facing; }
public Rover(RoverFacing roverFacing, Position roverPosition) : this() { RoverPosition = roverPosition; RoverFacing = roverFacing; }
public static RoverUnit StartExpedition(Map map, MapCoordinates startLocation, RoverFacing facing) { if (!map.CheckCoordinates(startLocation)) { throw new RoverCrashLandedException($"Rover crash landed on Mars, start location {startLocation.AsText()} unreachable on {map.AsText()} map"); } return(new RoverUnit(new RoverStatus(map.GetPosition(startLocation), facing), map)); }