### Question:
PiecewisePolynomialFunction1D { public DoubleArray differentiateTwice(PiecewisePolynomialResult pp, double xKey) { ArgChecker.notNull(pp, "pp"); ArgChecker.isFalse(pp.getOrder() < 3, "polynomial degree < 2"); DoubleArray knots = pp.getKnots(); int nCoefs = pp.getOrder(); int rowCount = pp.getDimensions() * pp.getNumberOfIntervals(); int colCount = nCoefs - 2; DoubleMatrix coef = DoubleMatrix.of( rowCount, colCount, (i, j) -> pp.getCoefMatrix().get(i, j) * (nCoefs - j - 1) * (nCoefs - j - 2)); PiecewisePolynomialResult ppDiff = new PiecewisePolynomialResult(knots, coef, nCoefs - 1, pp.getDimensions()); return evaluate(ppDiff, xKey); } PiecewisePolynomialFunction1D(); DoubleArray evaluate(PiecewisePolynomialResult pp, double xKey); DoubleMatrix evaluate(PiecewisePolynomialResult pp, double[] xKeys); DoubleMatrix[] evaluate(PiecewisePolynomialResult pp, double[][] xKeys); DoubleArray differentiate(PiecewisePolynomialResult pp, double xKey); DoubleMatrix differentiate(PiecewisePolynomialResult pp, double[] xKeys); DoubleArray differentiateTwice(PiecewisePolynomialResult pp, double xKey); DoubleMatrix differentiateTwice(PiecewisePolynomialResult pp, double[] xKeys); double integrate(PiecewisePolynomialResult pp, double initialKey, double xKey); DoubleArray integrate(PiecewisePolynomialResult pp, double initialKey, double[] xKeys); ValueDerivatives evaluateAndDifferentiate(PiecewisePolynomialResult pp, double xKey);  }### Answer:
@Test public void linearFuncDiffTwiceTest() { DoubleMatrix coefsMatrix = DoubleMatrix.copyOf( new double[][] {{1., -3.}, {0., 5.}, {1., 0.}, {0., 5.}, {1., 3.}, {0., 5.}}); double[] xKeys = new double[] {-2, 1, 2, 2.5}; final int dim = 2; final int nCoefs = 2; PiecewisePolynomialResult pp = new PiecewisePolynomialResult(X_VALUES, coefsMatrix, nCoefs, dim); PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D(); assertThatIllegalArgumentException() .isThrownBy(() -> function.differentiateTwice(pp, xKeys[0])); }
@Test public void linearFuncDiffTwiceMultiTest() { DoubleMatrix coefsMatrix = DoubleMatrix.copyOf( new double[][] {{1., -3.}, {0., 5.}, {1., 0.}, {0., 5.}, {1., 3.}, {0., 5.}}); double[] xKeys = new double[] {-2, 1, 2, 2.5}; final int dim = 2; final int nCoefs = 2; PiecewisePolynomialResult pp = new PiecewisePolynomialResult(X_VALUES, coefsMatrix, nCoefs, dim); PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D(); assertThatIllegalArgumentException() .isThrownBy(() -> function.differentiateTwice(pp, xKeys)); }