VectorialCovariance implements Serializable { public void increment(double[] v) throws DimensionMismatchException { if (v.length != sums.length) { throw new DimensionMismatchException(v.length, sums.length); } int k = 0; for (int i = 0; i < v.length; ++i) { sums[i] += v[i]; for (int j = 0; j <= i; ++j) { productsSums[k++] += v[i] * v[j]; } } n++; } VectorialCovariance(int dimension, boolean isBiasCorrected); void increment(double[] v); RealMatrix getResult(); long getN(); void clear(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testMismatch() { try { new VectorialCovariance(8, true).increment(new double[5]); Assert.fail("an exception should have been thrown"); } catch (DimensionMismatchException dme) { Assert.assertEquals(5, dme.getArgument()); Assert.assertEquals(8, dme.getDimension()); } }