VectorialMean implements Serializable { public void increment(double[] v) throws DimensionMismatchException { if (v.length != means.length) { throw new DimensionMismatchException(v.length, means.length); } for (int i = 0; i < v.length; ++i) { means[i].increment(v[i]); } } VectorialMean(int dimension); void increment(double[] v); double[] getResult(); long getN(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testMismatch() { try { new VectorialMean(8).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()); } }
@Test public void testSerial() { VectorialMean stat = new VectorialMean(points[0].length); for (int i = 0; i < points.length; ++i) { stat.increment(points[i]); } Assert.assertEquals(stat, TestUtils.serializeAndRecover(stat)); }