<commit_before>package com.tinkerpop.blueprints.generator;

import com.tinkerpop.blueprints.AbstractBlueprintsTest;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Property;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.StreamFactory;
import org.apache.commons.configuration.Configuration;
import org.javatuples.Pair;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

/**
 * @author <NAME> (http://stephen.genoprime.com)
 */
@RunWith(Enclosed.class)
public class CommunityGeneratorTest {

    @RunWith(Parameterized.class)
    public static class DifferentDistributionsTest extends AbstractBlueprintsTest {

        @Parameterized.Parameters(name = "{index}: {0}.test({1},{2})")
        public static Iterable<Object[]> data() {
            return Arrays.asList(new Object[][]{
                    {new NormalDistribution(2), new PowerLawDistribution(2.4), 0.1},
                    {new NormalDistribution(2), new PowerLawDistribution(2.4), 0.5},
                    {new NormalDistribution(2), new NormalDistribution(4), 0.5},
                    {new NormalDistribution(2), new NormalDistribution(4), 0.1},
                    {new PowerLawDistribution(2.3), new PowerLawDistribution(2.4), 0.2},
                    {new PowerLawDistribution(2.3), new NormalDistribution(4), 0.2}
            });
        }

        @Parameterized.Parameter(value = 0)
        public Distribution communityDistribution;

        @Parameterized.Parameter(value = 1)
        public Distribution degreeDistribution;

        @Parameterized.Parameter(value = 2)
        public double crossPcent;

        private static final int numberOfVertices = 100;

        @Test
        public void shouldGenerateRandomGraph() throws Exception {
            final CommunityGenerator generator = new CommunityGenerator("knows");
            communityGeneratorTest(g, generator);

            final Configuration configuration = graphProvider.newGraphConfiguration("g1");
            final Graph g1 = graphProvider.openTestGraph(configuration);
            prepareGraph(g1);
            final CommunityGenerator generator1 = new CommunityGenerator("knows");
            communityGeneratorTest(g1, generator1);

            assertNotEquals(StreamFactory.stream(g.query().edges()).count(), StreamFactory.stream(g1.query().edges()).count());

            // ensure that not every vertex has the same number of edges between graphs
            assertFalse(StreamFactory.stream(g.query().vertices())
                    .map(v -> Pair.with(v.getValue("oid"), StreamFactory.stream(v.query().direction(Direction.BOTH).edges()).count()))
                    .allMatch(p -> {
                        final Vertex v = g1.query().has("oid", p.getValue0()).vertices().iterator().next();
                        return p.getValue1() == StreamFactory.stream(v.query().direction(Direction.BOTH).edges()).count();
                    }));

            graphProvider.clear(g1, configuration);
        }

        @Test
        public void shouldGenerateSameGraph() throws Exception {
            final CommunityGenerator generator = new CommunityGenerator("knows", null , null, ()->123456789l);
            communityGeneratorTest(g, generator);

            final Configuration configuration = graphProvider.newGraphConfiguration("g1");
            final Graph g1 = graphProvider.openTestGraph(configuration);
            prepareGraph(g1);
            final CommunityGenerator generator1 = new CommunityGenerator("knows", null , null, ()->123456789l);
            communityGeneratorTest(g1, generator1);

            assertEquals(StreamFactory.stream(g.query().edges()).count(), StreamFactory.stream(g1.query().edges()).count());

            // ensure that every vertex has the same number of edges between graphs.
            assertTrue(StreamFactory.stream(g.query().vertices())
                    .map(v -> Pair.with(v.getValue("oid"), StreamFactory.stream(v.query().direction(Direction.BOTH).edges()).count()))
                    .allMatch(p -> {
                        final Vertex v = g1.query().has("oid", p.getValue0()).vertices().iterator().next();
                        return p.getValue1() == StreamFactory.stream(v.query().direction(Direction.BOTH).edges()).count();
                    }));

            graphProvider.clear(g1, configuration);
        }

        @Override<commit_msg>Tried to make the community generate tests less apt to fail randomly.<commit_after>package com.tinkerpop.blueprints.generator;

import com.tinkerpop.blueprints.AbstractBlueprintsTest;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.StreamFactory;
import org.apache.commons.configuration.Configuration;
import org.javatuples.Pair;
import org.javatuples.Triplet;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

/**
 * @author <NAME> (http://stephen.genoprime.com)
 */
@RunWith(Enclosed.class)
public class CommunityGeneratorTest {

    @RunWith(Parameterized.class)
    public static class DifferentDistributionsTest extends AbstractBlueprintsTest {

        @Parameterized.Parameters(name = "{index}: {0}.test({1},{2})")
        public static Iterable<Object[]> data() {
            return Arrays.asList(new Object[][]{
                    {new NormalDistribution(2), new PowerLawDistribution(2.4), 0.1},
                    {new NormalDistribution(2), new PowerLawDistribution(2.4), 0.5},
                    {new NormalDistribution(2), new NormalDistribution(4), 0.5},
                    {new NormalDistribution(2), new NormalDistribution(4), 0.1},
                    {new PowerLawDistribution(2.3), new PowerLawDistribution(2.4), 0.2},
                    {new PowerLawDistribution(2.3), new NormalDistribution(4), 0.2}
            });
        }

        @Parameterized.Parameter(value = 0)
        public Distribution communityDistribution;

        @Parameterized.Parameter(value = 1)
        public Distribution degreeDistribution;

        @Parameterized.Parameter(value = 2)
        public double crossPcent;

        private static final int numberOfVertices = 100;

        @Test
        public void shouldGenerateRandomGraph() throws Exception {
            final CommunityGenerator generator = new CommunityGenerator("knows");
            communityGeneratorTest(g, generator);

            final Configuration configuration = graphProvider.newGraphConfiguration("g1");
            final Graph g1 = graphProvider.openTestGraph(configuration);
            prepareGraph(g1);
            final CommunityGenerator generator1 = new CommunityGenerator("knows");
            communityGeneratorTest(g1, generator1);

            assertNotEquals(StreamFactory.stream(g.query().edges()).count(), StreamFactory.stream(g1.query().edges()).count());

            // ensure that not every vertex has the same number of edges between graphs
            assertFalse(StreamFactory.stream(g.query().vertices())
                    .map(v -> Triplet.with(v.getValue("oid"), StreamFactory.stream(v.query().direction(Direction.IN).edges()).count(),
                            StreamFactory.stream(v.query().direction(Direction.OUT).edges()).count()))
                    .allMatch(p -> {
                        final Vertex v = g1.query().has("oid", p.getValue0()).vertices().iterator().next();
                        return p.getValue1() == StreamFactory.stream(v.query().direction(Direction.IN).edges()).count()
                                && p.getValue2() == StreamFactory.stream(v.query().direction(Direction.OUT).edges()).count();
                    }));

            graphProvider.clear(g1, configuration);
        }

        @Test
        public void shouldGenerateSameGraph() throws Exception {
            final CommunityGenerator generator = new CommunityGenerator("knows", null , null, ()->123456789l);
            communityGeneratorTest(g, generator);

            final Configuration configuration = graphProvider.newGraphConfiguration("g1");
            final Graph g1 = graphProvider.openTestGraph(configuration);
            prepareGraph(g1);
            final CommunityGenerator generator1 = new CommunityGenerator("knows", null , null, ()->123456789l);
            communityGeneratorTest(g1, generator1);

            assertEquals(StreamFactory.stream(g.query().edges()).count(), StreamFactory.stream(g1.query().edges()).count());

            // ensure that every vertex has the same number of edges between graphs.
            assertTrue(StreamFactory.stream(g.query().vertices())
                    .map(v -> Triplet.with(v.getValue("oid"), StreamFactory.stream(v.query().direction(Direction.IN).edges()).count(),
                            StreamFactory.stream(v.query().direction(Direction.OUT).edges()).count()))
                    .allMatch(p -> {
                        final Vertex v = g1.query().has("oid", p.getValue0()).vertices().iterator().next();
                        return p.getValue1() == StreamFactory.stream(v.query().direction(Direction.IN).edges()).count()
                                && p.getValue2() == StreamFactory.stream(v.query().direction(Direction.OUT).edges()).count();
                    }));

            graphProvider.clear(g1, configuration);
        }

        @Override
{'fraction_non_alphanumeric': 0.1233217304823471, 'fraction_numerical': 0.015713575335653904, 'mean_word_length': 2.8033282904689862, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5112435', 'n_tokens_mistral': 2628, 'n_tokens_neox': 2458, 'n_words': 498}