public void ProcessRoverTwoInstructions_Returns_CorrectPosition(string instructions) { IRover rover = new Domain.MarsRover("two", 3, 3, 'E'); rover.ProcessInstructions(instructions); Assert.AreEqual($"Rover two: 5,1, E", rover.ToString()); }
public void SpinRoverRight_Returns_NewPosition(char currentDirection, char expectedDirection) { IRover rover = new Domain.MarsRover("one", 1, 1, currentDirection); rover.SpinRight(); Assert.AreEqual($"Rover one: 1,1, {expectedDirection}", rover.ToString()); }
public void ProcessRoverOneInstructions_Returns_CorrectPosition(string instructions) { IRover rover = new Domain.MarsRover("one", 1, 2, 'N'); rover.ProcessInstructions(instructions); Assert.AreEqual($"Rover one: 1,3, N", rover.ToString()); }
public void MoveRoverOutsidePlateau_Returns_SamePosition(int xCoordinate, int yCoordinate, char compassDirection) { IRover rover = new Domain.MarsRover("one", xCoordinate, yCoordinate, compassDirection); rover.Move(); Assert.AreEqual($"Rover one: {xCoordinate},{yCoordinate}, {compassDirection}", rover.ToString()); }
public void TestMethod2() { var marsRoverEndPosition = new Domain.MarsRover(new Rover(new Plateau(5, 5), new Location(new Coordinate(3, 3), DirectionEnum.E), "MMRMMRMRRM", new List <Coordinate>(), 1)).ExecuteCommands(); Assert.AreEqual( "5 1 E", $@"{marsRoverEndPosition.EndLocation.Coordinate.X} {marsRoverEndPosition.EndLocation.Coordinate.Y} {marsRoverEndPosition.EndLocation.Heading.ToString()}"); }
public void MoveRover_Returns_NewPosition( int xCoordinate, int yCoordinate, char compassDirection, int expectedXCoordinate, int expectedYCoordinate ) { IRover rover = new Domain.MarsRover("one", xCoordinate, yCoordinate, compassDirection); rover.Move(); Assert.AreEqual($"Rover one: {expectedXCoordinate},{expectedYCoordinate}, {compassDirection}", rover.ToString()); }
public Task <DomainMarsRover> Get(string roverId) { return(Task.Run(() => { var obj = new Domain.MarsRover(); if (_cache.TryGetValue <Domain.MarsRover>(roverId, out obj)) { obj.Message = $"Rover {roverId} was found"; } return obj; })); }
static void Main(string[] args) { IRover roverOne = new Domain.MarsRover("one", 1, 2, 'N'); string roverOneInstructions = "LMLMLMLMM"; roverOne.ProcessInstructions(roverOneInstructions); Console.WriteLine(roverOne.ToString()); IRover roverTwo = new Domain.MarsRover("two", 3, 3, 'E'); string roverTwoInstructions = "MMRMMRMRRM"; roverTwo.ProcessInstructions(roverTwoInstructions); Console.WriteLine(roverTwo.ToString()); }
public IActionResult Get(string id) { Domain.MarsRover result = this._marsGetService.Get(id).Result; if (string.IsNullOrEmpty(result?.RoverId)) { return(NotFound()); } MarsRoverResponse response = new MarsRoverResponse() { Message = result.Message, CurrentPosition = $"({result.CurrentPositionX},{result.CurrentPositionY})" }; return(Ok(response)); }
public IActionResult MovementRover(MovementRequest movement) { char[] validLetters = { 'L', 'R', 'M' }; var notChars = movement.MovementInstruction.Where( item => !char.IsLetter(item) || !validLetters.Contains(item) ); if (notChars.Count() > 0) { return(NotFound("MovementInstruction must contain only R,L and M")); } Domain.MarsRover result = this._marsUpdateService.UpdateMovement(movement).Result; MarsRoverResponse response = new MarsRoverResponse() { Message = result.Message, CurrentPosition = $"({result.CurrentPositionX},{result.CurrentPositionY})" }; return(Ok(response)); }
public IActionResult GetFakeMarsRover() { Domain.MarsRover result = this._marsGetService.GetFake().Result; return(Ok(result)); }
public void GetMarsRoverPosition_Returns_PositionString() { IRover rover = new Domain.MarsRover("one", 1, 3, 'N'); Assert.AreEqual("Rover one: 1,3, N", rover.ToString()); }
static void Main(string[] args) { try { Console.WriteLine("Enter the height of the plateau. For example: 5"); int y; while (!int.TryParse(Console.ReadLine(), out y)) { Console.WriteLine("Enter the height of the plateau. For example: 5."); } Console.WriteLine("Enter the width of the plateau. For example: 5"); int x; while (!int.TryParse(Console.ReadLine(), out x)) { Console.WriteLine("Enter the width of the plateau. For example: 5."); } Console.WriteLine("How many Rovers will be scanning the plateau?"); int z; while (!int.TryParse(Console.ReadLine(), out z)) { Console.WriteLine("How many Rovers will be scanning the plateau? Please enter only numbers"); } var hazards = new List <Coordinate>(); for (int i = 0; i < z; i++) { Console.WriteLine($@"Enter the landing X coordinate of rover {i + 1}."); int xx; while (!int.TryParse(Console.ReadLine(), out xx)) { Console.WriteLine($@"Enter the landing X coordinate of rover {i + 1}."); } Console.WriteLine($@"Enter the landing Y coordinate of rover {i + 1}."); int yy; while (!int.TryParse(Console.ReadLine(), out yy)) { Console.WriteLine($@"Enter the landing Y coordinate of rover {i + 1}."); } string zz; Console.WriteLine($@"Enter the landing direction of rover {i + 1}. Format: N, S, W or E"); while (true) { zz = Console.ReadLine(); if (!Regex.IsMatch(zz, "[^NSWE]")) { Console.WriteLine($@"Enter the landing direction of rover {i + 1}. Format: N, S, W or E"); break; } } Console.WriteLine($@"Enter the Commands you want rover {i + 1} to execute. Format: MRLM (M = move, R = turn right, L = turn left). No spaces."); string commands = Console.ReadLine(); var result = new Domain.MarsRover(new Rover(new Plateau(x, y), new Location(new Coordinate(xx, yy), (DirectionEnum)Enum.Parse(typeof(DirectionEnum), zz)), commands, hazards, i + 1)) ?.ExecuteCommands(); if (result?.EndLocation?.Coordinate == null) { Console.WriteLine("We were unable to track your rover with the instructions you entered. Press any key to exit."); return; } if (result.IsSuccess) { Console.WriteLine( $@"Rover {i + 1} will be stopping on {result.EndLocation.Coordinate.X} {result.EndLocation.Coordinate.Y} {result.EndLocation.Heading.ToString()}." ); hazards.Add(new Coordinate(result.EndLocation.Coordinate.X, result.EndLocation.Coordinate.Y)); } Console.WriteLine(result.Message); } Console.ReadLine(); } catch (Exception e) { Console.WriteLine("Something went terribly wrong and spun the squad in an orbit around Jupiter. Press enter to exit the program and try again."); Console.ReadLine(); } }