public TolerantDoubleComparison isWithin(double tolerance) {
    return new TolerantDoubleComparison() {
      @Override
      public void of(double expected) {
        Double actual = DoubleSubject.this.actual;
        checkNotNull(
            actual, "actual value cannot be null. tolerance=%s expected=%s", tolerance, expected);
        checkTolerance(tolerance);

        if (!equalWithinTolerance(actual, expected, tolerance)) {
          failWithoutActual(
              fact("expected", doubleToString(expected)),
              butWas(),
              fact("outside tolerance", doubleToString(tolerance)));
        }
      }
    };
  }
@Test
  public void isWithinZeroTolerance() {
    double max = Double.MAX_VALUE;
    assertThat(max).isWithin(0.0).of(max);
    assertThat(NEARLY_MAX).isWithin(0.0).of(NEARLY_MAX);
    assertThatIsWithinFails(max, 0.0, NEARLY_MAX);
    assertThatIsWithinFails(NEARLY_MAX, 0.0, max);

    double negativeMax = -1.0 * Double.MAX_VALUE;
    assertThat(negativeMax).isWithin(0.0).of(negativeMax);
    assertThat(NEGATIVE_NEARLY_MAX).isWithin(0.0).of(NEGATIVE_NEARLY_MAX);
    assertThatIsWithinFails(negativeMax, 0.0, NEGATIVE_NEARLY_MAX);
    assertThatIsWithinFails(NEGATIVE_NEARLY_MAX, 0.0, negativeMax);

    double min = Double.MIN_VALUE;
    assertThat(min).isWithin(0.0).of(min);
    assertThat(OVER_MIN).isWithin(0.0).of(OVER_MIN);
    assertThatIsWithinFails(min, 0.0, OVER_MIN);
    assertThatIsWithinFails(OVER_MIN, 0.0, min);

    double negativeMin = -1.0 * Double.MIN_VALUE;
    assertThat(negativeMin).isWithin(0.0).of(negativeMin);
    assertThat(UNDER_NEGATIVE_MIN).isWithin(0.0).of(UNDER_NEGATIVE_MIN);
    assertThatIsWithinFails(negativeMin, 0.0, UNDER_NEGATIVE_MIN);
    assertThatIsWithinFails(UNDER_NEGATIVE_MIN, 0.0, negativeMin);
  }