@Test
public void testNaN() {

    final TDigest digest = factory().create();
    Random gen = getRandom();
    final int iters = gen.nextInt(100);
    for (int i = 0; i < iters; ++i) {
        digest.add(gen.nextDouble(), 1 + gen.nextInt(10));
    }
    try {
        // both versions should fail
        if (gen.nextBoolean()) {
            digest.add(Double.NaN);
        } else {
            digest.add(Double.NaN, 1);
        }
        fail("NaN should be an illegal argument");
    } catch (IllegalArgumentException e) {
        // expected
    }
}