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 isWithinOf() {
    assertThat(2.0).isWithin(0.0).of(2.0);
    assertThat(2.0).isWithin(0.00001).of(2.0);
    assertThat(2.0).isWithin(1000.0).of(2.0);
    assertThat(2.0).isWithin(1.00001).of(3.0);
    assertThatIsWithinFails(2.0, 0.99999, 3.0);
    assertThatIsWithinFails(2.0, 1000.0, 1003.0);
    assertThatIsWithinFails(2.0, 1000.0, Double.POSITIVE_INFINITY);
    assertThatIsWithinFails(2.0, 1000.0, Double.NaN);
    assertThatIsWithinFails(Double.NEGATIVE_INFINITY, 1000.0, 2.0);
    assertThatIsWithinFails(Double.NaN, 1000.0, 2.0);
  }