@Test
public void smaRandomDataTest() {

    int length = (int) (Math.random() * 1000 + 1); // uniform random in [1..1000]
    double[] data = createRandomArray(length);
    int window = (int) (Math.random() * length);
    window = Math.max(window, 2);
    window = Math.min(window, length);
    double[] average = TimeSeriesUtilities.simpleMovingAverage(data, window);
    assertEquals("average has right length", data.length - window + 1, average.length);
    for (int i = 0; i < average.length; ++i) {
        double sum = 0.0;
        for (int j = 0; j < window; ++j) {
            sum += data[i + j];
        }
        double mean = sum / window;
        assertEquals("moving average is correct", mean, average[i], 1.0e-10);
    }
}