@Test
    public void testBigMerge() {
        Random r = new Random(260379);

        TreeMap<Integer, Integer> leftSet = new TreeMap<Integer, Integer>();
        TreeMap<Integer, Integer> rightSet = new TreeMap<Integer, Integer>();

        // There must be collisions and also some omissions
        for(int i=0; i < 4001; i++) {
            leftSet.put(r.nextInt(4000),  r.nextInt(1000));
            rightSet.put(r.nextInt(4000),  r.nextInt(1000));
        }

        // Compose
        ArrayList<Integer> leftArray = new ArrayList<Integer>(4000);
        for(Map.Entry<Integer ,Integer> e : leftSet.entrySet()) {
            for(int j=0; j<e.getValue(); j++) leftArray.add(e.getKey());
        }
        ArrayList<Integer> rightArray = new ArrayList<Integer>(4000);
        for(Map.Entry<Integer ,Integer> e : rightSet.entrySet()) {
            for(int j=0; j<e.getValue(); j++) rightArray.add(e.getKey());
        }


        DiscreteDistribution leftDist = new DiscreteDistribution(toIntArray(leftArray));
        DiscreteDistribution rightDist = new DiscreteDistribution(toIntArray(rightArray));
        DiscreteDistribution mergedDist1 = DiscreteDistribution.merge(leftDist, rightDist);
        DiscreteDistribution mergedDist2 = DiscreteDistribution.merge(rightDist, leftDist);

        for(int i=0; i < 5000; i++) {
            int lc = (leftSet.containsKey(i) ? leftSet.get(i) : 0);
            int rc = (rightSet.containsKey(i) ? rightSet.get(i) : 0);

            assertEquals(lc, leftDist.getCount(i));
            assertEquals(rc, rightDist.getCount(i));
            assertEquals(lc + rc, mergedDist1.getCount(i));
            assertEquals(lc + rc, mergedDist2.getCount(i));

        }
    }