@Test
public void merge() throws CMSMergeException, FrequencyException
{

    int numToMerge = 5;
    int cardinality = 1000000;
    double epsOfTotalCount = 0.0001;
    double confidence = 0.99;
    int seed = 7364181;
    int maxScale = 20;
    Random r = new Random();
    TreeSet<Integer> vals = new TreeSet<Integer>();
    CountMinSketchAlt baseline = new CountMinSketchAlt(epsOfTotalCount, confidence, seed);
    CountMinSketchAlt[] sketchs = new CountMinSketchAlt[numToMerge];
    for (int i = 0; i < numToMerge; i++)
    {
        sketchs[i] = new CountMinSketchAlt(epsOfTotalCount, confidence, seed);
        for (int j = 0; j < cardinality; j++)
        {
            int scale    = r.nextInt(maxScale);
            int val      = r.nextInt(1 << scale);
            vals.add(val);
            sketchs[i].add(val, 1);
            baseline.add(val, 1);
        }
    }
    CountMinSketchAlt merged = CountMinSketchAlt.merge(sketchs);
    assertEquals(baseline.size(), merged.size());
    assertEquals(baseline.getConfidence(), merged.getConfidence(), baseline.getConfidence() / 100);
    assertEquals(baseline.getRelativeError(), merged.getRelativeError(), baseline.getRelativeError() / 100);
    for (int val : vals)
    {
        assertEquals(baseline.estimateCount(val), merged.estimateCount(val));
    }
}