### Question:
KMeans { public <W extends Weighted<RealVector>> Centers compute(List<W> points, int numClusters, RandomGenerator randomGenerator) { Preconditions.checkArgument(numClusters > 0); Centers initial = initStrategy.apply(points, numClusters, randomGenerator); Centers updated = updateStrategy.update(points, initial); if (initial.size() != updated.size()) { LOG.warn(String.format( "Centers collapsed: client requested %d centers, but only %d were found", initial.size(), updated.size())); } return updated; } KMeans();  KMeans(
      KMeansInitStrategy initStrategy,
      KMeansUpdateStrategy updateStrategy); Centers compute(List<W> points, int numClusters,
                                                RandomGenerator randomGenerator);  }### Answer:
@Test public void testKmeansCompute() throws Exception { RandomGenerator rg = RandomManager.getRandom(); KMeans kmeans = new KMeans(KMeansInitStrategy.PLUS_PLUS, new LloydsUpdateStrategy(100)); Centers centers = kmeans.compute(points, 2, rg); assertEquals(new Centers(Vectors.of(1.5, 1.0), Vectors.of(4.5, 3.5)), centers); kmeans = new KMeans(KMeansInitStrategy.RANDOM, new LloydsUpdateStrategy(100)); centers = kmeans.compute(degeneratePoints, 3, rg); assertEquals(new Centers(Vectors.of(1.0, 1.0)), centers); }