@Test
public void testUpdate() {

  MultiNormal f = new MultiNormal(20);
  Vector a = f.sample();
  Vector b = f.sample();
  Vector c = f.sample();
  DenseVector x = new DenseVector(a);
  Centroid x1 = new Centroid(1, x);
  x1.update(new Centroid(2, new DenseVector(b)));
  Centroid x2 = new Centroid(x1);
  x1.update(c);
  // check for correct value
  Vector mean = a.plus(b).plus(c).assign(Functions.div(3));
  assertEquals(0, x1.getVector().minus(mean).norm(1), 1.0e-8);
  assertEquals(3, x1.getWeight(), 0);
  assertEquals(0, x2.minus(a.plus(b).divide(2)).norm(1), 1.0e-8);
  assertEquals(2, x2.getWeight(), 0);
  assertEquals(0, new Centroid(x1.getIndex(), x1, x1.getWeight()).minus(x1).norm(1), 1.0e-8);
  // and verify shared storage
  assertEquals(0, x.minus(x1).norm(1), 0);
  assertEquals(3, x1.getWeight(), 1.0e-8);
  assertEquals(1, x1.getIndex());
}