@Test
    public void testAliasMethod() {

        final float[] weights = initWeights(1000);
        ChiVertex<Integer, Float> vert = new ChiVertex<Integer, Float>(0, new VertexDegree(0, weights.length)) {
            public Float getOutEdgeValue(int i) {
                return weights[i];
            }

            @Override
            public int getOutEdgeId(int i) {
                return i;
            }

            @Override
            public int numOutEdges() {
                return weights.length;
            }
        };

        int n = 10000000;
        int[] hops = WeightedHopper.generateRandomHopsAliasMethodOut(new Random(260379), vert, n);

        assertEquals(hops.length, n);

        /* Now check the distribution makes sense */
        int[] counts = new int[weights.length];

        for(int i=0; i < hops.length; i++) {
            assertTrue(hops[i] >= 0 && hops[i] < weights.length);
            counts[hops[i]]++;
        }

        float totalWeight = 0.0f;
        for(int j=0; j < weights.length; j++) totalWeight += weights[j];


        for(int j=0; j < weights.length; j++) {
            int expected = (int) (n * weights[j]  / totalWeight);
            assertTrue(Math.abs(expected - counts[j]) < n / weights.length);  // dubious
        }
    }