GeometricMeanCalculator extends Function1D<double[], Double> { @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); Validate.isTrue(x.length > 0, "x cannot be empty"); final int n = x.length; double mult = x[0]; for (int i = 1; i < n; i++) { mult *= x[i]; } return Math.pow(mult, 1. / n); }  @Override Double evaluate(final double[] x);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullArray() { GEOMETRIC.evaluate((double[]) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyArray() { GEOMETRIC.evaluate(new double[0]); }
@Test public void test() { assertEquals(GEOMETRIC.evaluate(FLAT), 2, 0); assertEquals(GEOMETRIC.evaluate(X), Math.exp(ARITHMETIC.evaluate(LN_X)), 1e-15); }