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

        /* First create some data  */
        ArrayList<Integer> workArr = new ArrayList<Integer>();
        TreeMap<Integer, Integer> countToId = new TreeMap<Integer, Integer>(new Comparator<Integer>() {
            public int compare(Integer integer, Integer integer1) {
                return -integer.compareTo(integer1);
            }
        });
        for(int i=1; i < 200; i++) {
            int n;
            do {
                n = r.nextInt(10000);
            } while (countToId.containsKey(n)); // Unique count keys
            countToId.put(n, i);
            insertMultiple(workArr, i, n);
        }
        DiscreteDistribution dist = new DiscreteDistribution(toIntArray(workArr));


        /* Then insert some edges to avoid */
        int[] avoids = new int[] {0, 2, 4, 32,33, 66, 67,68,  99, 102, 184};
        DiscreteDistribution avoidDistr = DiscreteDistribution.createAvoidanceDistribution(avoids);

        // Test the merge works both ways
        DiscreteDistribution mergedL = DiscreteDistribution.merge(dist, avoidDistr);
        DiscreteDistribution mergedR = DiscreteDistribution.merge(avoidDistr, dist);

        for(int a : avoids) {
            assertEquals(-1, avoidDistr.getCount(a));
            assertEquals(-1, mergedL.getCount(a));
            assertEquals(-1, mergedR.getCount(a));
        }

        IdCount[] top = dist.getTop(10);
        int j = 0;
        HashSet<Integer> avoidSet = new HashSet<Integer>();
        for(int a : avoids) avoidSet.add(a);
        for(Map.Entry <Integer, Integer> e : countToId.entrySet()) {
            IdCount topEntryJ = top[j];

            if (!avoidSet.contains(e.getKey())) {
                assertEquals((int)e.getValue(), topEntryJ.id);
                assertEquals((int)e.getKey(), topEntryJ.count);
                j++;
                if (top.length <= j) {
                    assertEquals(10, j);
                    break;
                }
            }
        }
    }