void () { final Int2ObjectMap<String> fileIdToName = generateFileNames(ENOUGH_ENTRIES_TO_CHECK); final Map<String, IntArraySet> etalon = CollectionFactory.createSmallMemoryFootprintMap(); for (Int2ObjectMap.Entry<String> e : fileIdToName.int2ObjectEntrySet()) { final int fileId = e.getIntKey(); final String fileName = e.getValue(); index.addFileName(fileId, fileName); etalon.computeIfAbsent(fileName, _name -> new IntArraySet()) .add(fileId); } int surplus = 0; for (String fileName : new HashSet<>(fileIdToName.values())) { final IntArraySet trueFileIds = etalon.get(fileName); final IntArraySet fileIdsFromIndex = lookupIndexByFileName(index, fileName); surplus += fileIdsFromIndex.size() - trueFileIds.size(); } //Single collision probability is ~1-exp(-ENTRIES^2/2^33) ~ 1e-4 = 0.01% (see birthday paradox) final double collisionProbability = -Math.expm1(-(ENOUGH_ENTRIES_TO_CHECK * 1.0 * ENOUGH_ENTRIES_TO_CHECK) / 2.0 / 2.0 / Integer.MAX_VALUE); // put strong upper bound on false positives count: final double falsePositivesProbabilityUpperBound = 4 * collisionProbability; assertTrue( "Expect < " + falsePositivesProbabilityUpperBound + " 'false positives' fraction, " + "but got " + (surplus * 1.0 / ENOUGH_ENTRIES_TO_CHECK) + " (" + surplus + " FP out of " + ENOUGH_ENTRIES_TO_CHECK + " total entries)", surplus <= falsePositivesProbabilityUpperBound * ENOUGH_ENTRIES_TO_CHECK ); }