@Test
public void ks() {

    Random r = new Random();
    double mean = 0;
    double s2 = 0;
    for (int i = 0; i < 10; i++) {
        MergingDigest d1 = new MergingDigest(100);
        MergingDigest d2 = new MergingDigest(100);
        MergingDigest d3 = new MergingDigest(100);
        for (int j = 0; j < 1000000; j++) {
            d1.add(r.nextGaussian());
            d2.add(r.nextGaussian() + 1);
            d3.add(r.nextGaussian());
        }
        double ks = Comparison.ks(d1, d2);
        // this value is slightly lower than it should be (by about 0.9)
        assertEquals(269.5, ks, 3);
        double newMean = mean + (ks - mean) / (i + 1);
        s2 += (ks - mean) * (ks - newMean);
        mean = newMean;
        assertEquals(0, Comparison.ks(d1, d3), 3.5);
    }
    System.out.printf("%.5f %.5f\n", mean, Math.sqrt(s2 / 10));
}