Repository: apple/pkl
File: pkl-core/src/main/java/org/pkl/core/stdlib/test/report/SimpleReport.java (Java)

Code before:
            builder,
            result.errors(),
            "\n",
            error -> appendPadded(builder, error.exception().getMessage(), failurePadding));
      }
    }
  }

  private static void appendPadded(AnsiStringBuilder builder, String lines, String padding) {
    StringUtils.joinToStringBuilder(
        builder,
        lines.lines().collect(Collectors.toList()),
        "\n",
        str -> {
          if (!str.isEmpty()) builder.append(padding).append(str);
        });
  }

  private void makeStatsLine(
      AnsiStringBuilder sb, String kind, int total, int failed, boolean isFailed) {
    var passed = total - failed;
    var passRate = total > 0 ? 100.0 * passed / total : 0.0;

    if (failed > 0) {
      // visual bug: 9,999/10,000 appears to round to 100% so nudge it back down
      passRate = Math.min(passRate, 99.9);
    }
    var passRateLine = String.format(Locale.ROOT, "%.1f%% %s pass", passRate, kind);

    var color = isFailed ? AnsiCode.RED : AnsiCode.GREEN;
    sb.append(color, () -> sb.append(passRateLine));

    if (isFailed) {
      sb.append(" [").append(failed).append('/').append(total).append(" failed]");
    } else {
      sb.append(" [").append(passed).append(" passed]");
    }
  }
}


Review comment (bug):
I think a better approach here is to use proper math. Something like:
```java
var passRate = 0.0;
if (total > 0) {
  var passed = new BigDecimal(total - failed);
  var hundred = new BigDecimal(100);
  var totalPrecise = new BigDecimal(total);
  passRate = hundred.multiply(passed).divide(totalPrecise, 1, RoundingMode.DOWN).doubleValue()
}
```
A scale of 1 should be enough for our use case.

Code after:
            failure -> appendPadded(builder, failure.message(), failurePadding));
        StringUtils.joinToStringBuilder(
            builder,
            result.errors(),
            "\n",
            error -> appendPadded(builder, error.exception().getMessage(), failurePadding));
      }
    }
  }

  private static void appendPadded(AnsiStringBuilder builder, String lines, String padding) {
    StringUtils.joinToStringBuilder(
        builder,
        lines.lines().collect(Collectors.toList()),
        "\n",
        str -> {
          if (!str.isEmpty()) builder.append(padding).append(str);
        });
  }

  private void makeStatsLine(
      AnsiStringBuilder sb, String kind, int total, int failed, boolean isFailed) {
    var passed = total - failed;
    var passRate = "0.0";
    if (total > 0) {
      var passedDecimal = new BigDecimal(passed);
      var hundred = new BigDecimal(100);
      var totalPrecise = new BigDecimal(total);
      passRate =
          hundred.multiply(passedDecimal).divide(totalPrecise, 1, RoundingMode.DOWN).toString();
    }
    var passRateLine = String.format(Locale.ROOT, "%s%% %s pass", passRate, kind);

    var color = isFailed ? AnsiCode.RED : AnsiCode.GREEN;
    sb.append(color, () -> sb.append(passRateLine));

    if (isFailed) {
      sb.append(" [").append(failed).append('/').append(total).append(" failed]");
    } else {
      sb.append(" [").append(passed).append(" passed]");
    }
  }
}