public static void main(String args[]) { MovingAverage m = new MovingAverage(3); System.out.println(m.next(1)); // = 1 System.out.println(m.next(10)); // / = (1 + 10) / 2 System.out.println(m.next(3)); // = (1 + 10 + 3) / 3 System.out.println(m.next(5)); // = (10 + 3 + 5) / 3 }
private void runTest(List<Integer> inputs, List<Double> expectedOutputs) { expect(input.getName()).andReturn("test").atLeastOnce(); for (int value : inputs) { expect(input.read()).andReturn(value); } control.replay(); MovingAverage<Integer> movingAvg = MovingAverage.of(input, 10 /* window size */); for (double output : expectedOutputs) { assertThat(movingAvg.sample(), is(output)); } }