public void Rover_Should_Throw_Exception_When_Position_Value_Is_Incorrect(string upperBound, string position) { Plateu plateu = new Plateu(upperBound); Action action = () => new Rover(position, plateu); action.Should().Throw <ArgumentException>(); }
public async Task <IActionResult> ExploreMars([FromBody] InputModel input) { try { Plateu plateu = new Plateu(input.SizeX, input.SizeY); foreach (var commandSet in input.CommandSets) { Rover rover = new Rover(commandSet.DeployLocation.X, commandSet.DeployLocation.Y, commandSet.DeployLocation.Orientation); plateu.DeployRover(rover); rover.ProcessCommand(commandSet.Command); //Bazı ek kontroller için eklemiştim, assigment ta gerek olmadığı için kapattım. Map kısmı zaten kullanılmayacak. //plateu.UpdateMap(); } OutputModel output = new OutputModel(); foreach (var rover in plateu.Rovers) { output.statutes.Add(new RoverStatus() { X = rover.XLocation, Y = rover.YLocation, orientation = rover.Orientation }); } return(Ok(output)); } catch (Exception e) { return(BadRequest(e)); } }
public void Rover_Should_Move_Correctly_When_Instructued(string upperBound, string position, string movement, string result) { Plateu plateu = new Plateu(upperBound); Rover rover = new Rover(position, plateu); rover.CommandRover(movement); rover.ToString().Should().Be(result); }
public void Rover_Should_Give_The_Correct_Direction_Data_When_Turned(string upperBound, string position, string movement, string result) { Plateu plateu = new Plateu(upperBound); Rover rover = new Rover(position, plateu); rover.CommandRover(movement); rover.ToString().Should().Be(result); }
public void Rover_Should_Throw_Exception_When_Movement_Value_Is_Incorrect(string upperBound, string position, string movement) { Plateu plateu = new Plateu(upperBound); Rover rover = new Rover(position, plateu); Action action = () => rover.CommandRover(movement); action.Should().Throw <ArgumentException>(); }
public void Rover_Should_Throw_Exception_When_Out_Of_Bounds(string upperBound, string position, string movement) { Plateu plateu = new Plateu(upperBound); Rover rover = new Rover(position, plateu); Action action = () => rover.CommandRover(movement); action.Should().Throw <IndexOutOfRangeException>(); }
public void Given_Test_Cases_Should_Pass(string upperBound, string position, string movement, string result) { Plateu plateu = new Plateu(upperBound); Rover rover = new Rover(position, plateu); rover.CommandRover(movement); rover.ToString().Should().Be(result); }
public void SetInitialSize_ShouldNotThrowException_WhenSetPlateuSize() { var plateu = new Plateu(); var expectNull = Record.Exception(() => plateu.SetInitialSize("5 5")); Assert.Null(expectNull); }
public static void PrintResult(Plateu plateu) { Console.WriteLine("Result: "); foreach (Rover rvr in plateu.GetAllRovers()) { Console.WriteLine(rvr.GetCurrentPosition()); } Console.WriteLine("Press any key to exit"); Console.ReadLine(); }
private void SetRover(string plateuString, string positionString) { upperRightPoint = ConversionHelper.ToPoint(plateuString); lowerLeftPoint = ConversionHelper.DefaultPoint(); plateuArea = new PlateuArea(upperRightPoint, lowerLeftPoint); plateu = new Plateu(plateuArea); string pos = positionString; position = ConversionHelper.ToPoint(ConversionHelper.ExtractPointFromPosition(pos)); direction = ConversionHelper.ToDirection(ConversionHelper.ExtractDirectionFromPosition(pos)); rover = new Rover(position, direction); }
static void Main(string[] args) { var serviceProvider = new ServiceCollection() // different rover will be created for different callers .AddTransient <IRover, Rover>() // same objects can be used through same flow(http request in web apis) .AddScoped <MoveOrder>() .AddScoped <TurnRightOrder>() .AddScoped <TurnLeftOrder>() // selecting correct order handler with strategy-like pattern .AddScoped <Func <Orders, IOrder> >(orderProvider => key => { switch (key) { case Orders.Move: return(orderProvider.GetRequiredService <MoveOrder>()); case Orders.TurnRight: return(orderProvider.GetRequiredService <TurnRightOrder>()); case Orders.TurnLeft: return(orderProvider.GetRequiredService <TurnLeftOrder>()); default: throw new ArgumentException("Not valid OrderHandler."); } }) .BuildServiceProvider(); // there is no validation for input.txt file. it is assumed to be valid for this project. string[] lines = File.ReadAllLines("input.txt"); var boundaries = lines[0].Split(" "); var plateu = new Plateu(0, 0, Convert.ToInt32(boundaries[0]), Convert.ToInt32(boundaries[1])); for (int i = 1; i < lines.Length; i += 2) { var roverInfo = lines[i].Split(" "); var rover = serviceProvider.GetRequiredService <IRover>(); rover.Initialize(plateu, Convert.ToInt32(roverInfo[0]), Convert.ToInt32(roverInfo[1]), (Directions)char.Parse(roverInfo[2])); var orders = lines[i + 1].ToCharArray().Select(c => (Orders)c); var orderHandler = serviceProvider.GetRequiredService <Func <Orders, IOrder> >(); foreach (var order in orders) { orderHandler(order).Execute(rover); } Console.WriteLine(rover.GetPositionString()); } }
public void Invalid_Rover_Position_Test() { upperRightPoint = ConversionHelper.ToPoint("100 100"); lowerLeftPoint = ConversionHelper.DefaultPoint(); plateuArea = new PlateuArea(upperRightPoint, lowerLeftPoint); plateu = new Plateu(plateuArea); string pos = "101 101 S"; position = ConversionHelper.ToPoint(ConversionHelper.ExtractPointFromPosition(pos)); direction = ConversionHelper.ToDirection(ConversionHelper.ExtractDirectionFromPosition(pos)); rover = new Rover(position, direction); Assert.False(rover.IsValidPosition(plateuArea)); }
static void Main() { try { Plateu plateu = Execution.GetPlateuData(); Execution.PrintResult(plateu); } catch (Exception ex) { MessageHelper.ErrorMessage(ex.Message); throw; } }
static async Task Main(string[] args) { try { var platueInformation = Console.ReadLine().Split(' '); var platue = new Plateu(new Position() { XCoordinate = Convert.ToInt32(platueInformation[0]), YCoordinate = Convert.ToInt32(platueInformation[1]), }); Console.WriteLine("How many rovers?"); var roverCount = Convert.ToInt32(Console.ReadLine()); var rovers = new List <IRover>(); while (roverCount > 0) { Console.WriteLine("Please Enter Rover Information!"); var roverInformation = Console.ReadLine().Split(' '); var rover = new Rover() { XCoordinate = Convert.ToInt32(roverInformation[0]), YCoordinate = Convert.ToInt32(roverInformation[1]), CardinalCompassPointType = (CardinalCompassPointType)Enum.Parse(typeof(CardinalCompassPointType), roverInformation[2]), Movements = Console.ReadLine().GetMovements(), }; rovers.Add(rover); roverCount--; } var commandService = new CommandService(); await commandService.ProcessAsync(rovers).ConfigureAwait(true); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Request successful."); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(ex.Message); } finally { Console.ReadKey(); } }
public static Plateu GetPlateuData() { ConsoleKeyInfo key; PlateuArea plateuArea = GetPlateuArea(); Plateu plateu = new Plateu(plateuArea); do { Rover rover = GetRover(); if (rover.IsValidPosition(plateuArea) && TryNavigate(ref rover, plateuArea)) { plateu.AddRover(rover); } else { MessageHelper.ErrorMessage("Position is out of Plateu !!!"); } Console.WriteLine("Do you want to start new rover?Y/N"); key = Console.ReadKey(true); } while (key.Key != ConsoleKey.N); return(plateu); }
public void OutOfBoundsTest(params string[] input) { var boundaries = input[0].Split(" "); var plateu = new Plateu(0, 0, Convert.ToInt32(boundaries[0]), Convert.ToInt32(boundaries[1])); Assert.Throws <OutOfBoundsException>(() => { for (int i = 1; i < input.Length; i += 2) { var roverInfo = input[i].Split(" "); var rover = new Rover(); rover.Initialize(plateu, Convert.ToInt32(roverInfo[0]), Convert.ToInt32(roverInfo[1]), (Directions)char.Parse(roverInfo[2])); var orders = input[i + 1].ToCharArray().Select(c => (Orders)c); foreach (var order in orders) { _orderHandler(order).Execute(rover); } Console.WriteLine(rover.GetPositionString()); } }); }
public void Plateu_Should_Correctly_Determine_If_Rover_Is_In_It_Or_Not(string upperBound, int roverX, int roverY, bool expectedValue) { Plateu plateu = new Plateu(upperBound); plateu.IsRoverInPlateu(roverX, roverY).Should().Be(expectedValue); }
public void SetInitialSize_ShouldFormatException_WhenPlateuIsEmpty() { var plateu = new Plateu(); Assert.Throws <FormatException>(() => plateu.SetInitialSize("")); }
public static Rover CreateRover(int id, int coordinateX, int coordinateY, char direction, string command, Plateu plateu) { return(new Rover(id, coordinateX, coordinateY, direction, command, plateu)); }
public void SetInitialSize_ShouldFormatException_WhenPlateuIsIncludeCharacter() { var plateu = new Plateu(); Assert.Throws <FormatException>(() => plateu.SetInitialSize("5 a")); }