public void ShouldRoverLaunchAsExpected(string roverCoordinate) { // arrange _mockPlateau.Setup(x => x.ValidateRoverPosition(It.IsAny <Point>())).Returns(true); var plateau = new MarsRover.Domain.Plateau(); var rover = new MarsRover.Domain.MarsRover(); // act var plateauSize = "0 0"; plateau.InitializePlateau(plateauSize); rover.Launch(_mockPlateau.Object, roverCoordinate); var roverPosition = roverCoordinate.Split(' '); int.TryParse(roverPosition[0], out int xPosition); int.TryParse(roverPosition[1], out int yPosition); var roverDirection = roverPosition[2][0]; _directionDict = new Dictionary <char, Direction> { { 'N', Direction.North }, { 'E', Direction.East }, { 'S', Direction.South }, { 'W', Direction.West } }; // assert Assert.AreEqual(rover.RoverPosition.X, xPosition); Assert.AreEqual(rover.RoverPosition.Y, yPosition); Assert.AreEqual(rover.RoverDirection, _directionDict[roverDirection]); }
public void ConvertInputFromFile(string fileName) { if (string.IsNullOrEmpty(fileName)) { Console.WriteLine("File path is empty!"); return; } int lineIndex = 0; string line; // Read the file and display it line by line. using (var fileStream = File.OpenRead(fileName)) { using (System.IO.StreamReader file = new System.IO.StreamReader(fileStream)) { Console.WriteLine("**********INPUT**********"); while ((line = file.ReadLine()) != null) { if (lineIndex == 0) { this.PlateauInput = Plateau.Parse(line); } if (lineIndex > 0 && lineIndex % 2 == 1) { this.RoverCommandInputList.Add(new ConvertedRoverCommandInput { Rover = Rover.Parse(line) }); } else if (lineIndex > 0 && lineIndex % 2 == 0) { if (this.RoverCommandInputList.Last()?.Rover != null) { this.RoverCommandInputList.Last().CommandInput = line; } } lineIndex++; System.Console.WriteLine(line); } file.Close(); }; } }
public void ShouldPlateauInitializeAsExpected(string plateauSize) { // arrange _mockPlateau.Setup(x => x.ValidateRoverPosition(It.IsAny <Point>())).Returns(true); var plateau = new MarsRover.Domain.Plateau(); // act plateau.InitializePlateau(plateauSize); var inputs = plateauSize.Split(' '); int.TryParse(inputs[0], out var width); int.TryParse(inputs[1], out var height); // assert Assert.AreEqual(plateau.Width, width); Assert.AreEqual(plateau.Height, height); }
public void Move(Plateau plateau = null) { switch (DirectionType) { case DirectionType.N: if (plateau == null || (plateau != null && plateau.EndingCoordinates.Y > Position.Y)) { Position.Y += 1; } break; case DirectionType.E: if (plateau == null || (plateau != null && plateau.EndingCoordinates.X > Position.X)) { Position.X += 1; } break; case DirectionType.S: if (plateau == null || (plateau != null && plateau.StartingCoordinates.Y < Position.Y)) { Position.Y -= 1; } break; case DirectionType.W: if (plateau == null || (plateau != null && plateau.StartingCoordinates.X < Position.X)) { Position.X -= 1; } break; default: break; } }