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 TwoTheSameLawnSizesShouldBeEqual() { var lawnSize1 = new LawnSize(5, 10); var lawnSize2 = new LawnSize(5, 10); (lawnSize1.Equals(lawnSize2)) .Should() .BeTrue(); }
public void TwoDifferentLawnSizesShouldNotBeEqual() { var lawnSize1 = new LawnSize(5, 10); var lawnSize2 = new LawnSize(10, 10); (lawnSize1.Equals(lawnSize2)) .Should() .BeFalse(); }
public void IsPositionWithinLawn_ShouldReturnTrueWhenPositionIsWithin( int positionX, int positionY) { var lawnSize = new LawnSize(5, 10); var position = new Position(positionX, positionY); lawnSize .IsPositionWithinLawn(position) .Should() .BeTrue(); }
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); }
protected bool Equals(LawnSize other) { return RightmostCoordinate == other.RightmostCoordinate && TopmostCoordinate == other.TopmostCoordinate; }
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); }
protected bool Equals(LawnSize other) { return(RightmostCoordinate == other.RightmostCoordinate && TopmostCoordinate == other.TopmostCoordinate); }