@Test public void averageRatioOfMultipleRatiosCanBeCalculated() { assertThat(Ratio.average(asList(new Ratio(1.0), new Ratio(2.0), new Ratio(3.0), new Ratio(4.0)))) .isApproximatelyEqualTo(new Ratio(2.5), ALLOWED_OFFSET); assertThat(Ratio.average(asList(new Ratio(1.0), new Ratio(-1.0)))).isApproximatelyEqualTo(new Ratio(0.0), ALLOWED_OFFSET); assertThat(Ratio.average(asList(new Ratio(-2.0), new Ratio(-4.0)))).isApproximatelyEqualTo(new Ratio(-3.0), ALLOWED_OFFSET); }
public static Ratio average(final Iterable<Ratio> rates) throws IllegalArgumentException { double sum = 0; int count = 0; for (final Ratio rate : rates) { count += 1; sum += rate.value; } if (count == 0) { throw new IllegalArgumentException( "The iterator containing the ratios thats average should be calculated contained no ratios."); } return new Ratio(sum / count); }
Ratio implements Comparable<Ratio> { public static Ratio average(final Iterable<Ratio> rates) throws IllegalArgumentException { double sum = 0; int count = 0; for (final Ratio rate : rates) { count += 1; sum += rate.value; } if (count == 0) { throw new IllegalArgumentException( "The iterator containing the ratios thats average should be calculated contained no ratios."); } return new Ratio(sum / count); } }
Ratio implements Comparable<Ratio> { public static Ratio average(final Iterable<Ratio> rates) throws IllegalArgumentException { double sum = 0; int count = 0; for (final Ratio rate : rates) { count += 1; sum += rate.value; } if (count == 0) { throw new IllegalArgumentException( "The iterator containing the ratios thats average should be calculated contained no ratios."); } return new Ratio(sum / count); } Ratio(final double value);  Ratio(final double value, final RatioUnit unit); }
Ratio implements Comparable<Ratio> { public static Ratio average(final Iterable<Ratio> rates) throws IllegalArgumentException { double sum = 0; int count = 0; for (final Ratio rate : rates) { count += 1; sum += rate.value; } if (count == 0) { throw new IllegalArgumentException( "The iterator containing the ratios thats average should be calculated contained no ratios."); } return new Ratio(sum / count); } Ratio(final double value);  Ratio(final double value, final RatioUnit unit); double asBasic(); static Ratio average(final Iterable<Ratio> rates); @Override int compareTo(final Ratio other); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString(); }
Ratio implements Comparable<Ratio> { public static Ratio average(final Iterable<Ratio> rates) throws IllegalArgumentException { double sum = 0; int count = 0; for (final Ratio rate : rates) { count += 1; sum += rate.value; } if (count == 0) { throw new IllegalArgumentException( "The iterator containing the ratios thats average should be calculated contained no ratios."); } return new Ratio(sum / count); } Ratio(final double value);  Ratio(final double value, final RatioUnit unit); double asBasic(); static Ratio average(final Iterable<Ratio> rates); @Override int compareTo(final Ratio other); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString(); static final Ratio MIN_VALUE; }