private static string PerformSimulation( LawnMowerState initialState, LawnSize lawnSize, LawnMowerCommand[] commands) { var simulator = new LawnMowerMovementSimulator(); try { var lawnMowerSteps = simulator.SimulateMovement( initialState, lawnSize, commands); var finalState = lawnMowerSteps .Last(); return($"{finalState.Position.X} {finalState.Position.Y} {finalState.Direction.Sign}"); } catch (CannotMoveOutsideLawnBoundariesException) { return("Mower tried to cut rare plants"); } }
public void TwoDifferentLawnSizesShouldNotBeEqual() { var lawnSize1 = new LawnSize(5, 10); var lawnSize2 = new LawnSize(10, 10); (lawnSize1.Equals(lawnSize2)) .Should() .BeFalse(); }
public void TwoTheSameLawnSizesShouldBeEqual() { var lawnSize1 = new LawnSize(5, 10); var lawnSize2 = new LawnSize(5, 10); (lawnSize1.Equals(lawnSize2)) .Should() .BeTrue(); }
public async Task PostLawn([FromBody] LawnSize lawnData) { if (!ModelState.IsValid) { throw new InvalidOperationException("Invalid lawn data provided."); } await Task.Run(() => _lawnCommands.SetSize(lawnData.StartX, lawnData.StartX, lawnData.SizeX, lawnData.SizeY)).ConfigureAwait(false); }
public void IsPositionWithinLawn_ShouldReturnFalseWhenPositionIsNotWithin( int positionX, int positionY) { var lawnSize = new LawnSize(5, 10); var position = new Position(positionX, positionY); lawnSize .IsPositionWithinLawn(position) .Should() .BeFalse(); }
public IHttpActionResult GetLawn() { Direction orient = _lawnQuey.MachineDirection; ILocation loc = _lawnQuey.MachineLocation; int height = _lawnQuey.LawnHeight; int width = _lawnQuey.LawnWidth; LawnSize lawnInfo = new LawnSize() { SizeX = width, SizeY = height, StartX = loc.X, StartY = loc.Y }; return(Ok(lawnInfo)); }
public void ParseLawnSize_ShouldReturnCorrectLawnSizeWhenInputIsValid( string input, int expectedTopmostCoordinate, int expectedRightmostCoordinate) { var inputParser = new InputParser(); var lawnSize = inputParser.ParseLawnSize(input); var expectedLawnSize = new LawnSize( expectedRightmostCoordinate, expectedTopmostCoordinate); lawnSize .Should() .Be(expectedLawnSize); }
private IEnumerable <LawnMowerState> SimulateMovementImpl( LawnMowerState initialState, LawnSize lawnSize, IEnumerable <LawnMowerCommand> commands) { var currentState = initialState; foreach (var command in commands) { currentState = PerformCommand(currentState, command); if (!lawnSize.IsPositionWithinLawn(currentState.Position)) { throw new CannotMoveOutsideLawnBoundariesException(); } yield return(currentState); } }
public IEnumerable <LawnMowerState> SimulateMovement( LawnMowerState initialState, LawnSize lawnSize, IEnumerable <LawnMowerCommand> commands) { if (initialState == null) { throw new ArgumentNullException(nameof(initialState)); } if (lawnSize == null) { throw new ArgumentNullException(nameof(lawnSize)); } if (commands == null) { throw new ArgumentNullException(nameof(commands)); } // actual implementation is in separate method to force execution of arguments checks before iterating the result return(SimulateMovementImpl(initialState, lawnSize, commands)); }