void () { final long[] packedKeysValues = generateKeyValues(ENOUGH_ENTRIES); final Int2IntMultimap multimap = new Int2IntMultimap(); //Use Map[int -> Set[int]] as 'etalon' multimap implementation to compare against: final Int2ObjectMap<IntSet> etalon = new Int2ObjectOpenHashMap<>(); for (final long packedKeyValue : packedKeysValues) { final int key = key(packedKeyValue); final int value = value(packedKeyValue); multimap.put(key, value); etalon.computeIfAbsent(key, _k -> new IntOpenHashSet()).add(value); } final ThreadLocalRandom rnd = ThreadLocalRandom.current(); for (int i = 0; i < ENOUGH_ENTRIES; i++) { final int randomIndex = rnd.nextInt(packedKeysValues.length); final long packedKeyValue = packedKeysValues[randomIndex]; final int key = key(packedKeyValue); final int value = value(packedKeyValue); if (rnd.nextBoolean()) { multimap.put(key, value); etalon.computeIfAbsent(key, _k -> new IntOpenHashSet()).add(value); } else { multimap.remove(key, value); etalon.computeIfAbsent(key, _k -> new IntOpenHashSet()).remove(value); } } //now check content against etalon: for (final Int2ObjectMap.Entry<IntSet> e : etalon.int2ObjectEntrySet()) { final int key = e.getIntKey(); final IntSet etalonValues = e.getValue(); final IntOpenHashSet multimapValues = getValues(multimap, key); assertEquals( "key[" + key + "] values must be the same ", etalonValues, multimapValues ); } assertEquals( "Multimap size must be == number of unique (key,value) pairs", multimap.size(), etalon.values().stream().mapToInt(values -> values.size()).sum() ); }