### Question:
LeastSquaresRegression { protected void checkData(double[][] x, double[][] weights, double[] y) { checkData(x, y); if (weights != null) { if (weights.length == 0) { throw new IllegalArgumentException("No data in weights array"); } if (weights.length != x.length) { throw new IllegalArgumentException("Independent variable and weight arrays are not the same length"); } int n = weights[0].length; for (double[] w : weights) { if (w.length != n) { throw new IllegalArgumentException("Need a rectangular array of weight"); } } } }  abstract LeastSquaresRegressionResult regress(double[][] x, double[][] weights, double[] y, boolean useIntercept);  }### Answer:
@Test public void test() { final LeastSquaresRegression regression = new OrdinaryLeastSquaresRegression(); assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(null, null)); double[][] x1 = new double[0][0]; assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(x1, null)); double[] y1 = new double[0]; assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(x1, (double[]) null, y1)); double[][] x2 = new double[1][2]; double[] y2 = new double[3]; assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(x2, (double[]) null, y2)); double[][] x = new double[][] {{1., 2., 3.}, {4., 5.}, {6., 7., 8.}, {9., 0., 0.}}; assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(x, (double[]) null, y2)); x[1] = new double[] {4., 5., 6.}; assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(x, (double[]) null, y2)); double[] y3 = new double[] {1., 2., 3., 4.}; double[] w11 = new double[0]; assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(x, w11, y3)); double[][] w1 = new double[0][0]; assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(x, w1, y3)); double[] w12 = new double[3]; assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(x, w12, y3)); double[][] w2 = new double[3][0]; assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(x, w2, y3)); double[][] w3 = new double[][] {{1., 2., 3.}, {4., 5.}, {6., 7., 8.}, {9., 0., 0.}}; assertThatIllegalArgumentException() .isThrownBy(() -> regression.checkData(x, w3, y3)); }