public async Task <Robot> GetCurrentPosition(string robotId) { var robot = await _robotCache.GetCache(robotId); if (robot == null) { return(null); } return(robot); }
public void GivenARobotThatDoesNotExistsNullValueIsReturned() { _testRobot = null; _robotCache.GetCache(Arg.Any<string>()).Returns(_testRobot); var result = _robotMove.MoveRobot("123").Result; result.Should().Be(null); }
public async Task <Robot> MoveRobot(string robotId) { var currentRobot = await _robotCache.GetCache(robotId); if (currentRobot == null) { return(null); } var step = FinalizeRobotStepValue(currentRobot.FacingDirection); if (IsValidRobotFacingAxis(currentRobot, GeoDirection.North) || IsValidRobotFacingAxis(currentRobot, GeoDirection.South)) { if (IsWithinRange(currentRobot.YAxis, step, _config.RobotMaxRange, _config.RobotMinRange)) { currentRobot.YAxis += step; } } else { if (IsWithinRange(currentRobot.XAxis, step, _config.RobotMaxRange, _config.RobotMinRange)) { currentRobot.XAxis += step; } } _robotCache.StoreCache(currentRobot); return(currentRobot); }
public void GivenACallToCheckRobotInitializationItShouldBeFalseIfAllParametersAreNotSet() { _robotCache.GetCache(Arg.Any <string>()).Returns(_testRobot); var result = _robotInit.IsRobotInitialized("123").Result; result.Should().Be(false); }
public async Task <Robot> Turn(string robotId, TurnType turnType) { var robotMaxRange = _config.RobotMaxRange; var robotMinRange = _config.RobotMinRange; var robot = await _robotCache.GetCache(robotId); if (robot == null) { return(null); } int turn = (int)turnType; var newFacingPosition = (int)robot.FacingDirection + turn > robotMaxRange ? (int)GeoDirection.North : (int)robot.FacingDirection + turn; if ((GeoDirection)newFacingPosition == GeoDirection.NotSet) { newFacingPosition = (turn < robotMinRange) ? (int)GeoDirection.West : (int)GeoDirection.East; } robot.FacingDirection = (GeoDirection)newFacingPosition; _robotCache.StoreCache(robot); return(robot); }
public async Task <bool> IsRobotInitialized(string id) { var robot = await _robotCache.GetCache(id); return(robot != null && robot.XAxis > _config.ResetPositionValue && robot.YAxis > _config.ResetPositionValue && robot.FacingDirection != GeoDirection.NotSet); }