@Test
public void merge() throws CountMinHeavyHitter.CMHeavyHitterMergeException {

	int numToMerge = 5;
	long[] actualFreq = new long[maxScale];
	CountMinHeavyHitter merged = new CountMinHeavyHitter(fraction,error,confidence,seed);
	long totalCardinality = 0;
	CountMinHeavyHitter[] sketches = new CountMinHeavyHitter[numToMerge];
	for (int i = 0; i < numToMerge; i++) {
		CountMinSketch cms = new CountMinSketch(error, confidence, seed);
		sketches[i] = new CountMinHeavyHitter(cms, fraction);
		for (int j = 0; j < cardinality; j++) {
			int val;
			if (r.nextDouble()<0.1){
				val = r.nextInt(10);
			}else{
				val = r.nextInt(maxScale);
			}
			sketches[i].addObject(val);
			actualFreq[val]++;
			totalCardinality++;
		}
		merged.merge(sketches[i]);
	}
	Map<Object,Long> mergedHeavyHitters = merged.getHeavyHitters();
	long frequency = (long)(totalCardinality*fraction);
	for (int i = 0; i < actualFreq.length; ++i) {
		if (actualFreq[i] >= frequency) {
			assertTrue("All items with freq. > s.n will be found. Item " + i + ". Real freq. " + actualFreq[i] + " Expected freq." + frequency, mergedHeavyHitters.containsKey(i));
		}
	}
}