RollingAverage { public String toS() { final StringBuilder sb = new StringBuilder("Rolling Average: Size: " + Math.min(position, size) + "/" + size + " Average: " + average() + " "); for (int i = 0; i < size; i++) { sb.append(i); sb.append(":"); sb.append(values[i]); sb.append(" "); } return sb.toString(); } RollingAverage(final int size); synchronized double put(final double value); double average(); boolean reachedPeak(); String toS();  }
@Test public void instantTest() { final String[] results = { "Rolling Average: Size: 0/3 Average: 0.0 0:0.0 1:0.0 2:0.0 ", "Rolling Average: Size: 0/10 Average: 0.0 0:0.0 1:0.0 2:0.0 3:0.0 4:0.0 5:0.0 6:0.0 7:0.0 8:0.0 9:0.0 " }; final RollingAverage avg1 = new RollingAverage(3); assertWithMessage("inst 0").that(avg1.toS()).isEqualTo(results[0]); final RollingAverage avg2 = new RollingAverage(10); assertWithMessage("inst 1").that(avg2.toS()).isEqualTo(results[1]); }