public LawnMowerState ParseLawnMowerState( string input) { var match = LawnMowerStateRegex.Match(input); if (!match.Success) { throw new InvalidInputException($"Lawn mower initial state ({input}) is not in correct format"); } try { int x = int.Parse(match.Groups["X"].Value); int y = int.Parse(match.Groups["Y"].Value); char directionSign = match.Groups["DirectionSign"].Value[0]; var position = new Position(x, y); var direction = Direction.GetBySign(directionSign); return new LawnMowerState(position, direction); } catch (Exception e) { throw new InvalidInputException(e.Message); } }
public void GetAdjacentPosition_ShouldThrowWhenNullIsPassedIn() { var position = new Position(2, 3); Action call = () => position.GetAdjacentPosition(null); call.ShouldThrow<ArgumentNullException>(); }
public bool IsPositionWithinLawn( Position position) { return position.X >= 0 && position.X <= RightmostCoordinate && position.Y >= 0 && position.Y <= TopmostCoordinate; }
public void GetAdjacentPosition_ShouldReturnCorrectPosition() { var position = new Position(2, 3); var adjacentPosition = position.GetAdjacentPosition(Direction.North); adjacentPosition.X.Should().Be(2); adjacentPosition.Y.Should().Be(4); }
public LawnMowerState( Position position, Direction direction) { if (direction == null) { throw new ArgumentNullException(nameof(direction)); } Position = position; Direction = direction; }
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(); }