@Test
public void testReduce() {

    Vector mean1 = VectorUtils.of(1, 0);
    Vector mean2 = VectorUtils.of(0, 1);
    CovarianceMatricesAggregator agg11 = new CovarianceMatricesAggregator(mean1, identity(2), 1);
    CovarianceMatricesAggregator agg12 = new CovarianceMatricesAggregator(mean1, identity(2), 1);
    CovarianceMatricesAggregator agg21 = new CovarianceMatricesAggregator(mean2, identity(2), 2);
    CovarianceMatricesAggregator agg22 = new CovarianceMatricesAggregator(mean2, identity(2), 2);
    List<CovarianceMatricesAggregator> result = CovarianceMatricesAggregator.reduce(
        Arrays.asList(agg11, agg21),
        Arrays.asList(agg12, agg22)
    );
    assertEquals(2, result.size());
    CovarianceMatricesAggregator res1 = result.get(0);
    CovarianceMatricesAggregator res2 = result.get(1);
    assertArrayEquals(mean1.asArray(), res1.mean().asArray(), 1e-4);
    assertArrayEquals(identity(2).times(2).getStorage().data(), res1.weightedSum().getStorage().data(), 1e-4);
    assertEquals(2, res1.rowCount());
    assertArrayEquals(mean2.asArray(), res2.mean().asArray(), 1e-4);
    assertArrayEquals(identity(2).times(2).getStorage().data(), res2.weightedSum().getStorage().data(), 1e-4);
    assertEquals(4, res2.rowCount());
}