def _format_gaussian_report(result):
  """Formats a `_GaussianResult` as a complete report str.

  The information presented includes:
  - The parameters of the Gaussian fit
  - The extrapolated probability of the `assertAllMeansClose` failing,
    assuming the distribution of means is Gaussian
  - Suggested changes to the tolerance and, if possible, number of
    samples that should bring the failure rate to a desired point

  Args:
    result: A `_GaussianResult` capturing the fit.

  Returns:
    report: A Python  `str` suitable for being printed or added to an
      assertion message.
  """
  report = '\nAssuming also that the true distribution on means is Gaussian:'
  report += f'\n- Mean ~ N(loc={result.loc:.3g}, scale={result.scale:.3g}).'
  p_fail = result.too_low_p + result.too_high_p
  report += f'\n- p(fail) = {p_fail:.3g}.'
  for error_rate in [1e-3, 1e-9]:
    one_rate = result.for_error_rate(error_rate)
    if p_fail > error_rate:
      report += f'\n- To lower to {error_rate}, try '
    else:
      report += f'\n- To raise to {error_rate}, try '
    report += f'atol {one_rate.new_atol:.3g} or rtol {one_rate.new_rtol:.3g}'

    if one_rate.out_of_bounds:
      # No increase in the sample size will make this pass, unless it
      # also shifts the mean, which we cannot predict.
      report += '.'
    else:
      if one_rate.too_tight:
        # Even a million times fewer samples do not risk exiting the tolerances.
        report += '; the Gaussian is too tight on the scale of the tolerances.'
      elif one_rate.too_broad:
        # Even a huge number of samples predicts a bad error rate.
        report += '; the Gaussian is too broad on the scale of the tolerances.'
      else:
        report += (
            f', or {one_rate.samples_factor:.3g} times the samples.')
  return report