RatioGauge implements Gauge<Double> { @Override public Double getValue() { return getRatio().getValue(); }  @Override Double getValue();  }
@Test public void calculatesTheRatioOfTheNumeratorToTheDenominator() { final RatioGauge regular = new RatioGauge() { @Override protected Ratio getRatio() { return RatioGauge.Ratio.of(2, 4); } }; assertThat(regular.getValue()) .isEqualTo(0.5); }
@Test public void handlesDivideByZeroIssues() { final RatioGauge divByZero = new RatioGauge() { @Override protected Ratio getRatio() { return Ratio.of(100, 0); } }; assertThat(divByZero.getValue()) .isNaN(); }
@Test public void handlesInfiniteDenominators() { final RatioGauge infinite = new RatioGauge() { @Override protected Ratio getRatio() { return Ratio.of(10, Double.POSITIVE_INFINITY); } }; assertThat(infinite.getValue()) .isNaN(); }
@Test public void handlesNaNDenominators() { final RatioGauge nan = new RatioGauge() { @Override protected Ratio getRatio() { return Ratio.of(10, Double.NaN); } }; assertThat(nan.getValue()) .isNaN(); }