RollingAverage { public synchronized double put(final double value) { values[position % size] = value; position++; return average(); } RollingAverage(final int size); synchronized double put(final double value); double average(); boolean reachedPeak(); String toS();  }
@Test public void putTest() { final String results[] = { "Rolling Average: Size: 1/3 Average: 1.0 0:1.0 1:0.0 2:0.0 ", "Rolling Average: Size: 2/3 Average: 1.5 0:1.0 1:2.0 2:0.0 ", "Rolling Average: Size: 3/3 Average: 2.0 0:1.0 1:2.0 2:3.0 ", "Rolling Average: Size: 3/3 Average: 3.0 0:4.0 1:2.0 2:3.0 ", "Rolling Average: Size: 3/3 Average: 4.0 0:4.0 1:5.0 2:3.0 ", "Rolling Average: Size: 3/3 Average: 5.0 0:4.0 1:5.0 2:6.0 ", "Rolling Average: Size: 3/3 Average: 6.0 0:7.0 1:5.0 2:6.0 ", "Rolling Average: Size: 3/3 Average: 7.0 0:7.0 1:8.0 2:6.0 ", "Rolling Average: Size: 3/3 Average: 8.0 0:7.0 1:8.0 2:9.0 ", "Rolling Average: Size: 3/3 Average: 9.0 0:10.0 1:8.0 2:9.0 " }; final RollingAverage avg1 = new RollingAverage(3); for (int i = 1; i <= 10; i++) { avg1.put(i); assertWithMessage("avg " + i).that(avg1.toS()).isEqualTo(results[i - 1]); } }