QuartileSkewnessCalculator extends Function1D<double[], Double> { @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); final int n = x.length; Validate.isTrue(n >= 3, "Need at least three points to calculate interquartile range"); if (n == 3) { return (x[2] - 2 * x[1] + x[0]) / 2.; } final double[] copy = Arrays.copyOf(x, n); Arrays.sort(copy); double[] lower, upper; if (n % 2 == 0) { lower = Arrays.copyOfRange(copy, 0, n / 2); upper = Arrays.copyOfRange(copy, n / 2, n); } else { lower = Arrays.copyOfRange(copy, 0, n / 2 + 1); upper = Arrays.copyOfRange(copy, n / 2, n); } final double q1 = MEDIAN.evaluate(lower); final double q2 = MEDIAN.evaluate(x); final double q3 = MEDIAN.evaluate(upper); return (q1 - 2 * q2 + q3) / (q3 - q1); }  @Override Double evaluate(final double[] x);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNull() { SKEW.evaluate((double[]) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmpty() { SKEW.evaluate(new double[0]); }
@Test public void test() { Double t = SKEW.evaluate(NORMAL_DATA); assertEquals(t, 0, 0.1); t = SKEW.evaluate(CHI_SQ_DATA); assertFalse(Math.abs(t) < 0.1); }