def IsInTargetRange(
    target, error_ref, warning_percentage, error_percentage, value):
  """Test if a value falls into warning or error range around a target.

  Args:
    target: The target value.
    error_ref: The error reference as the base for warning/error percentage.
    warning_percentage: The percentage of error_ref to draw warning bounds.
    error_percentage: The percentage of error_ref to draw error bounds.
    value: The value of the variable.

  Returns:
    0 for normal, 1 for warning, and 2 or error.
  """
  warning_lower_bound = target - error_ref * warning_percentage
  warning_upper_bound = target + error_ref * warning_percentage
  error_lower_bound = target - error_ref * error_percentage
  error_upper_bound = target + error_ref * error_percentage

  if warning_lower_bound <= value <= warning_upper_bound:
    return 0
  elif error_lower_bound <= value <= error_upper_bound:
    return 1
  else:
    return 2