@Test
public void compareLogHistograms() {

    Random r = new Random();
    int failed = 0;
    try {
        Comparison.compareChi2(new LogHistogram(10e-6, 10), new LogHistogram(1e-6, 1));
        fail("Should have detected incompatible histograms (lower bound)");
    } catch (IllegalArgumentException e) {
        assertEquals("Incompatible histograms in terms of size or bounds", e.getMessage());
    }
    try {
        Comparison.compareChi2(new LogHistogram(10e-6, 10), new LogHistogram(10e-6, 1));
        fail("Should have detected incompatible histograms (size)");
    } catch (IllegalArgumentException e) {
        assertEquals("Incompatible histograms in terms of size or bounds", e.getMessage());
    }
    for (int i = 0; i < 1000; i++) {
        LogHistogram d1 = new LogHistogram(10e-6, 10);
        LogHistogram d2 = new LogHistogram(10e-6, 10);
        LogHistogram d3 = new LogHistogram(10e-6, 10);
        for (int j = 0; j < 10000; j++) {
            // these should look the same
            d1.add(Math.exp(r.nextGaussian()));
            d2.add(Math.exp(r.nextGaussian()));
            // can we see a small difference
            d3.add(Math.exp(r.nextGaussian() + 0.5));
        }
        // 144 degrees of freedom, Pr(llr > 250) < 1e-6
        if (Comparison.compareChi2(d1, d2) > 250) {
            failed++;
        }
        if (Comparison.compareChi2(d1, d3) < 1000) {
            failed++;
        }
    }
    assertEquals(0, failed, 5);
}