ExactCount { public ExactCount count(List<Datum> data) { for (Datum d : data) { for (int i : d.attributes()) { Double curVal = counts.get(i); if (curVal == null) { curVal = 0.; } counts.put(i, curVal + 1); } } return this; }  HashMap<Integer, Double> getCounts(); ExactCount count(List<Datum> data);  }
@Test public void testCount() { ExactCount ec = new ExactCount(); HashMap<Integer, Integer> truth = new HashMap<>(); List<Datum> dws = new ArrayList<>(); for (int i = 0; i < 100; ++i) { for (int j = 0; j < i; ++j) { dws.add(new Datum(Lists.newArrayList(i), new ArrayRealVector())); truth.compute(i, (k, v) -> v == null ? 1 : v + 1); } } ec.count(dws); for (Map.Entry<Integer, Double> cnt : ec.getCounts().entrySet()) { assertEquals(truth.get(cnt.getKey()), cnt.getValue(), 1e-10); } }