#pragma warning restore xUnit1010 // The value is not convertible to the method parameter type public void RotateLeftCommand_ValidPlateauValidRoverAndValidInstructions_ShouldBeEqualGivenResult(int width, int height, int xPosition, int yPosition, Directions direction, Directions result) { _plateauService = new PlateauService(); _roverService = new RoverService(_explorationFactoryMock); BaseModels <PlateauModel> basePlateauModel = _plateauService.Create(width, height); basePlateauModel.Data.Width.Should().Equals(width); basePlateauModel.Data.Height.Should().Equals(height); RoverLocationModel roverLocation = new RoverLocationModel() { Direction = direction, XPosition = xPosition, YPosition = yPosition }; BaseModels <RoverModel> baseRoverModel = _roverService.Initalize(basePlateauModel.Data, roverLocation); _explorationCommandMock = new RotateLeftCommand(); _explorationCommandMock.Explore(_roverService.GetCurrentRover().Data.Location); _roverService.GetCurrentRover().Data.Location.Direction.Should().Be(result); Console.WriteLine(result); Console.ReadLine(); }
public override void Run(ProcessModel processModel) { bool isValidate = false; _processModel = processModel; while (!isValidate) { Console.Write(string.Format(ConsoleSentences, processModel.RoverIndex)); EnterValue = Console.ReadLine().TrimStart().TrimEnd(); isValidate = Validate(); if (isValidate) { RoverLocationModel location = new RoverLocationModel() { Apsis = Convert.ToInt32(_apsisValue), Ordinate = Convert.ToInt32(_ordinateValue), Orientation = _orientationValue, MaxApsisLimit = processModel.PlateauModel.Apsis, MaxOrdinateLimit = processModel.PlateauModel.Ordinate }; processModel.CurrentRover = new RoverModel(); processModel.CurrentRover.Location = location; if (NextProcess != null) { NextProcess.Run(processModel); } } } }
static void Main(string[] args) { ServiceProvider serviceProvider = new ServiceCollection() .AddSingleton <IExplorationFactory, ExplorationFactory>() .AddSingleton <IExplorationCommand, RotateRightCommand>() .AddSingleton <IExplorationCommand, RotateLeftCommand>() .AddSingleton <IExplorationCommand, MoveForwardCommand>() .AddSingleton <IPlateauService, PlateauService>() .AddSingleton <IRoverService, RoverService>() .AddSingleton <IInstructionService, InstructionService>() .BuildServiceProvider(); IPlateauService plateauService = serviceProvider.GetService <IPlateauService>(); IRoverService roverService = serviceProvider.GetService <IRoverService>(); IInstructionService instructionService = serviceProvider.GetService <IInstructionService>(); List <RoverModel> rovers = new List <RoverModel>(); BaseModels <PlateauModel> basePlateauModel = plateauService.Create(5, 5); Console.WriteLine("5 5"); RoverLocationModel firstRoverLocation = new RoverLocationModel() { XPosition = 1, YPosition = 2, Direction = Directions.North }; Console.WriteLine("1 2 N"); BaseModels <RoverModel> baseRoverModel = roverService.Initalize(basePlateauModel.Data, firstRoverLocation); rovers.Add(baseRoverModel.Data); Console.WriteLine("LMLMLMLMM"); BaseModels <List <Instruction> > baseInstructionModel = instructionService.GetInstructions("LMLMLMLMM"); foreach (Instruction instruction in baseInstructionModel.Data) { roverService.ExplorePlateau(instruction); } Console.WriteLine("3 3 E"); RoverLocationModel secondRoverLocation = new RoverLocationModel() { XPosition = 3, YPosition = 3, Direction = Directions.East }; baseRoverModel = roverService.Initalize(basePlateauModel.Data, secondRoverLocation); rovers.Add(baseRoverModel.Data); Console.WriteLine("MMRMMRMRRM"); baseInstructionModel = instructionService.GetInstructions("MMRMMRMRRM"); foreach (Instruction instruction in baseInstructionModel.Data) { roverService.ExplorePlateau(instruction); } Console.ReadLine(); }
public BaseModels <RoverModel> Initalize(PlateauModel plateauModel, RoverLocationModel roverLocation) { BaseModels <RoverModel> model = new BaseModels <RoverModel>(); BaseModels <bool> validateLocationModel = ValidateLocation(plateauModel, roverLocation); if (validateLocationModel.Data) { model.Data = new RoverModel(); model.Data.Id = Guid.NewGuid(); model.Data.Location.Direction = roverLocation.Direction; model.Data.Location.XPosition = roverLocation.XPosition; model.Data.Location.YPosition = roverLocation.YPosition; CurrentRover = model.Data; Console.WriteLine("Rover initialized successfully."); } return(model); }
public void Explore(RoverLocationModel roverLocation) { switch (roverLocation.Direction) { case Directions.North: roverLocation.Direction = Directions.West; break; case Directions.East: roverLocation.Direction = Directions.North; break; case Directions.South: roverLocation.Direction = Directions.East; break; case Directions.West: roverLocation.Direction = Directions.South; break; } }
public void Explore(RoverLocationModel roverLocation) { switch (roverLocation.Direction) { case Directions.North: roverLocation.YPosition += 1; break; case Directions.East: roverLocation.XPosition += 1; break; case Directions.South: roverLocation.YPosition -= 1; break; case Directions.West: roverLocation.XPosition -= 1; break; } }
public BaseModels <bool> ValidateLocation(PlateauModel plateauModel, RoverLocationModel roverLocation) { BaseModels <bool> model = new BaseModels <bool>(); bool isValidDirection = IsValidDirection(roverLocation.Direction); bool isValidXPosition = IsValidXPosition(plateauModel.Width, roverLocation.XPosition); bool isValidYPosition = IsValidYPosition(plateauModel.Height, roverLocation.YPosition); if (isValidDirection && isValidXPosition && isValidYPosition) { model.Data = true; Console.WriteLine($"Given location ({roverLocation.XPosition}-{roverLocation.YPosition}-{roverLocation.Direction}) for the rover is valid on the given plateau ({plateauModel.Width}-{plateauModel.Height})."); } else { ValidateRoverLocationException exception = new ValidateRoverLocationException(); Console.WriteLine(exception.Message); throw exception; } return(model); }