<commit_before>package com.tinkerpop.blueprints;

import com.tinkerpop.blueprints.impls.GraphTest;

import java.util.HashSet;
import java.util.Set;

/**
 * @author <NAME> (http://markorodriguez.com)
 */
public class GraphQueryTestSuite extends TestSuite {

    public GraphQueryTestSuite() {
    }

    public GraphQueryTestSuite(final GraphTest graphTest) {
        super(graphTest);
    }

    public void testGraphQueryForVertices() {
        Graph graph = graphTest.generateGraph();
        if (graph.getFeatures().supportsVertexIndex && graph instanceof KeyIndexableGraph) {
            ((KeyIndexableGraph) graph).createKeyIndex("name", Vertex.class);
        }
        if (graph.getFeatures().supportsVertexProperties) {
            Vertex vertex = graph.addVertex(null);
            vertex.setProperty("name", "marko");
            vertex.setProperty("age", 33);
            vertex = graph.addVertex(null);
            vertex.setProperty("name", "matthias");
            vertex.setProperty("age", 28);
            graph.addVertex(null);

            Iterable<Vertex> vertices = graph.query().vertices();
            assertEquals(count(vertices), 3);
            assertEquals(count(vertices), 3);
            Set<String> names = new HashSet<String>();
            for (Vertex v : vertices) {
                names.add((String) v.getProperty("name"));
            }
            assertEquals(names.size(), 3);
            assertTrue(names.contains("marko"));
            assertTrue(names.contains(null));
            assertTrue(names.contains("matthias"));

            assertEquals(count(graph.query().limit(0).vertices()), 0);
            assertEquals(count(graph.query().limit(1).vertices()), 1);
            assertEquals(count(graph.query().limit(2).vertices()), 2);
            assertEquals(count(graph.query().limit(3).vertices()), 3);
            assertEquals(count(graph.query().limit(4).vertices()), 3);

            assertEquals(count(graph.query().limit(0).vertices()), count(graph.query().limit(0, 0).vertices()));
            BaseTest.equalIterators(graph.query().limit(0).vertices().iterator(), graph.query().limit(0, 0).vertices().iterator());
            assertEquals(count(graph.query().limit(1).vertices()), count(graph.query().limit(0, 1).vertices()));
            BaseTest.equalIterators(graph.query().limit(1).vertices().iterator(), graph.query().limit(0, 1).vertices().iterator());
            assertEquals(count(graph.query().limit(2).vertices()), count(graph.query().limit(0, 2).vertices()));
            BaseTest.equalIterators(graph.query().limit(2).vertices().iterator(), graph.query().limit(0, 2).vertices().iterator());
            assertEquals(count(graph.query().limit(3).vertices()), count(graph.query().limit(0, 3).vertices()));
            BaseTest.equalIterators(graph.query().limit(3).vertices().iterator(), graph.query().limit(0, 3).vertices().iterator());
            assertEquals(count(graph.query().limit(3).vertices()), count(graph.query().limit(0, 4).vertices()));
            BaseTest.equalIterators(graph.query().limit(3).vertices().iterator(), graph.query().limit(0, 4).vertices().iterator());

            assertEquals(count(graph.query().limit(0, 1).vertices()), 1);
            BaseTest.equalIterators(graph.query().limit(0, 1).vertices().iterator(), graph.query().limit(1).vertices().iterator());
            assertEquals(count(graph.query().limit(1, 1).vertices()), 1);
            assertEquals(count(graph.query().limit(1, 2).vertices()), 2);
            assertEquals(count(graph.query().limit(1, 3).vertices()), 2);
            assertEquals(count(graph.query().limit(1, 4).vertices()), 2);
            assertEquals(count(graph.query().limit(2, 3).vertices()), 1);
            assertEquals(count(graph.query().limit(4, 10).vertices()), 0);

            vertices = graph.query().has("name", "marko").vertices();
            assertEquals(count(vertices), 1);
            // TODO: Neo4j's global iterators are inconsistent with its transactions
            // assertEquals(vertices.iterator().next().getProperty("name"), "marko");

            vertices = graph.query().has("age", Query.Compare.GREATER_THAN_EQUAL, 29).vertices();
            assertEquals(count(vertices), 1);
            assertEquals(vertices.iterator().next().getProperty("name"), "marko");
            assertEquals(vertices.iterator().next().getProperty("age"), 33);

            vertices = graph.query().has("age", Query.Compare.GREATER_THAN_EQUAL, 28).vertices();
            assertEquals(count(vertices), 2);
            names = new HashSet<String>();
            for (Vertex v : vertices) {
                names.add((String) v.getProperty("name"));
            }
            assertEquals(names.size(), 2);
            assertTrue(names.contains("marko"));
            assertTrue(names.contains("matthias"));

            vertices = graph.query().interval("age", 28, 33).vertices();
            assertEquals(count(vertices), 1);
            assertEquals(vertices.iterator().next().getProperty("name"), "matthias");

            assertEquals(count(graph.query().hasNot("age").vertices()), 1);
            assertEquals(count(graph.query().has("age", 28).has("name", "matthias").vertices()), 1);
            assertEquals(count(graph.query().has("age", 28).has("name", "matthias").has("name", "matthias").vertices()), 1);
            assertEquals(count(graph.query().interval("age", 28, 32).has("name", "marko").vertices()), 0);
            graph.shutdown();
        }
    }

    public void testGraphQueryForEdges() {
        Graph graph = graphTest.generateGraph();
        if (graph.getFeatures().supportsEdgeIndex && graph instanceof KeyIndexableGraph) {
            ((KeyIndexableGraph) graph).createKeyIndex("type", Edge.class);
        }
        if (graph.getFeatures().supportsEdgeProperties && graph.getFeatures().supportsVertexProperties) {
            Vertex marko = graph.addVertex(null);
            marko.setProperty("name", "marko");
            Vertex matthias = graph.addVertex(null);
            matthias.setProperty("name", "matthias");
            Vertex stephen = graph.addVertex(null);
            stephen.setProperty("name", "stephen");

            Edge edge = marko.addEdge("knows", stephen);
            edge.setProperty("type", "tinkerpop");
            edge.setProperty("weight", 1.0);
            edge = marko.addEdge("knows", matthias);
            edge.setProperty("type", "aurelius");

            assertEquals(count(graph.query().edges()), 2);
            assertEquals(count(graph.query().limit(0).edges()), 0);
            assertEquals(count(graph.query().limit(1).edges()), 1);
            assertEquals(count(graph.query().limit(2).edges()), 2);
            assertEquals(count(graph.query().limit(3).edges()), 2);

            assertEquals(count(graph.query().has("type", "tinkerpop").has("type", "tinkerpop").edges()), 1);
            assertEquals(graph.query().has("type", "tinkerpop").edges().iterator().next().getProperty("weight"), 1.0);
            assertEquals(count(graph.query().has("type", "aurelius").edges()), 1);
            assertEquals(graph.query().has("type", "aurelius").edges().iterator().next().getPropertyKeys().size(), 1);
            assertEquals(count(graph.query().hasNot("weight").edges()), 1);
            assertEquals(graph.query().hasNot("weight").edges().iterator().next().getProperty("type"), "aurelius");

            assertEquals(count(graph.query().has("weight", 1.0).edges()), 1);
            assertEquals(graph.query().has("weight", 1.0).edges().iterator().next().getProperty("type"), "tinkerpop");
            assertEquals(count(graph.query().has("weight", 1.0).has("type", "tinkerpop").edges()), 1);
            assertEquals(graph.query().has("weight", 1.0).has("type", "tinkerpop").edges().iterator().next().getProperty("type"), "tinkerpop");
            assertEquals(count(graph.query().has("weight", 1.0).has("type", "aurelius").edges()), 0);

            assertEquals(graph.query().interval("weight", 0.0, 1.1).edges().iterator().next().getProperty("type"), "tinkerpop");
            assertEquals(count(graph.query().interval("weight", 0.0, 1.0).edges()), 0);
        }
        graph.shutdown();
    }

    public void testGraphQueryForHasOR() {
        Graph graph = graphTest.generateGraph();
        if (graph.getFeatures().supportsEdgeIndex && graph instanceof KeyIndexableGraph) {
            ((KeyIndexableGraph) graph).createKeyIndex("type", Edge.class);
        }
        if (graph.getFeatures().supportsEdgeProperties && graph.getFeatures().supportsVertexProperties) {
            Vertex marko = graph.addVertex(null);
            marko.setProperty("name", "marko");
            Vertex matthias = graph.addVertex(null);
            matthias.setProperty("name", "matthias");
            Vertex stephen = graph.addVertex(null);
            stephen.setProperty("name", "stephen");

            Edge edge = marko.addEdge("knows", stephen);
            edge.setProperty("type", "tinkerpop");
            edge.setProperty("weight", 1.0);
            edge = marko.addEdge("knows", matthias);
            edge.setProperty("type", "aurelius");

            assertEquals(count(graph.query().has("type", "tinkerpop", "aurelius").edges()), 2);
            assertEquals(count(graph.query().has("type", "tinkerpop", "aurelius").has("type", "tinkerpop").edges()), 1);
            assertEquals(count(graph.query().has("type", "tinkerpop", "aurelius").has("type", "tinkerpop").has("type", "aurelius").edges()), 0);

            assertEquals(graph.query().has("type", "tinkerpop", "aurelius").edges().iterator().next().getProperty("weight"), 1.0);<commit_msg>removed ordering assumption.<commit_after>package com.tinkerpop.blueprints;

import com.tinkerpop.blueprints.impls.GraphTest;

import java.util.HashSet;
import java.util.Set;

/**
 * @author <NAME> (http://markorodriguez.com)
 */
public class GraphQueryTestSuite extends TestSuite {

    public GraphQueryTestSuite() {
    }

    public GraphQueryTestSuite(final GraphTest graphTest) {
        super(graphTest);
    }

    public void testGraphQueryForVertices() {
        Graph graph = graphTest.generateGraph();
        if (graph.getFeatures().supportsVertexIndex && graph instanceof KeyIndexableGraph) {
            ((KeyIndexableGraph) graph).createKeyIndex("name", Vertex.class);
        }
        if (graph.getFeatures().supportsVertexProperties) {
            Vertex vertex = graph.addVertex(null);
            vertex.setProperty("name", "marko");
            vertex.setProperty("age", 33);
            vertex = graph.addVertex(null);
            vertex.setProperty("name", "matthias");
            vertex.setProperty("age", 28);
            graph.addVertex(null);

            Iterable<Vertex> vertices = graph.query().vertices();
            assertEquals(count(vertices), 3);
            assertEquals(count(vertices), 3);
            Set<String> names = new HashSet<String>();
            for (Vertex v : vertices) {
                names.add((String) v.getProperty("name"));
            }
            assertEquals(names.size(), 3);
            assertTrue(names.contains("marko"));
            assertTrue(names.contains(null));
            assertTrue(names.contains("matthias"));

            assertEquals(count(graph.query().limit(0).vertices()), 0);
            assertEquals(count(graph.query().limit(1).vertices()), 1);
            assertEquals(count(graph.query().limit(2).vertices()), 2);
            assertEquals(count(graph.query().limit(3).vertices()), 3);
            assertEquals(count(graph.query().limit(4).vertices()), 3);

            assertEquals(count(graph.query().limit(0).vertices()), count(graph.query().limit(0, 0).vertices()));
            BaseTest.equalIterators(graph.query().limit(0).vertices().iterator(), graph.query().limit(0, 0).vertices().iterator());
            assertEquals(count(graph.query().limit(1).vertices()), count(graph.query().limit(0, 1).vertices()));
            BaseTest.equalIterators(graph.query().limit(1).vertices().iterator(), graph.query().limit(0, 1).vertices().iterator());
            assertEquals(count(graph.query().limit(2).vertices()), count(graph.query().limit(0, 2).vertices()));
            BaseTest.equalIterators(graph.query().limit(2).vertices().iterator(), graph.query().limit(0, 2).vertices().iterator());
            assertEquals(count(graph.query().limit(3).vertices()), count(graph.query().limit(0, 3).vertices()));
            BaseTest.equalIterators(graph.query().limit(3).vertices().iterator(), graph.query().limit(0, 3).vertices().iterator());
            assertEquals(count(graph.query().limit(3).vertices()), count(graph.query().limit(0, 4).vertices()));
            BaseTest.equalIterators(graph.query().limit(3).vertices().iterator(), graph.query().limit(0, 4).vertices().iterator());

            assertEquals(count(graph.query().limit(0, 1).vertices()), 1);
            BaseTest.equalIterators(graph.query().limit(0, 1).vertices().iterator(), graph.query().limit(1).vertices().iterator());
            assertEquals(count(graph.query().limit(1, 1).vertices()), 1);
            assertEquals(count(graph.query().limit(1, 2).vertices()), 2);
            assertEquals(count(graph.query().limit(1, 3).vertices()), 2);
            assertEquals(count(graph.query().limit(1, 4).vertices()), 2);
            assertEquals(count(graph.query().limit(2, 3).vertices()), 1);
            assertEquals(count(graph.query().limit(4, 10).vertices()), 0);

            vertices = graph.query().has("name", "marko").vertices();
            assertEquals(count(vertices), 1);
            // TODO: Neo4j's global iterators are inconsistent with its transactions
            // assertEquals(vertices.iterator().next().getProperty("name"), "marko");

            vertices = graph.query().has("age", Query.Compare.GREATER_THAN_EQUAL, 29).vertices();
            assertEquals(count(vertices), 1);
            assertEquals(vertices.iterator().next().getProperty("name"), "marko");
            assertEquals(vertices.iterator().next().getProperty("age"), 33);

            vertices = graph.query().has("age", Query.Compare.GREATER_THAN_EQUAL, 28).vertices();
            assertEquals(count(vertices), 2);
            names = new HashSet<String>();
            for (Vertex v : vertices) {
                names.add((String) v.getProperty("name"));
            }
            assertEquals(names.size(), 2);
            assertTrue(names.contains("marko"));
            assertTrue(names.contains("matthias"));

            vertices = graph.query().interval("age", 28, 33).vertices();
            assertEquals(count(vertices), 1);
            assertEquals(vertices.iterator().next().getProperty("name"), "matthias");

            assertEquals(count(graph.query().hasNot("age").vertices()), 1);
            assertEquals(count(graph.query().has("age", 28).has("name", "matthias").vertices()), 1);
            assertEquals(count(graph.query().has("age", 28).has("name", "matthias").has("name", "matthias").vertices()), 1);
            assertEquals(count(graph.query().interval("age", 28, 32).has("name", "marko").vertices()), 0);
            graph.shutdown();
        }
    }

    public void testGraphQueryForEdges() {
        Graph graph = graphTest.generateGraph();
        if (graph.getFeatures().supportsEdgeIndex && graph instanceof KeyIndexableGraph) {
            ((KeyIndexableGraph) graph).createKeyIndex("type", Edge.class);
        }
        if (graph.getFeatures().supportsEdgeProperties && graph.getFeatures().supportsVertexProperties) {
            Vertex marko = graph.addVertex(null);
            marko.setProperty("name", "marko");
            Vertex matthias = graph.addVertex(null);
            matthias.setProperty("name", "matthias");
            Vertex stephen = graph.addVertex(null);
            stephen.setProperty("name", "stephen");

            Edge edge = marko.addEdge("knows", stephen);
            edge.setProperty("type", "tinkerpop");
            edge.setProperty("weight", 1.0);
            edge = marko.addEdge("knows", matthias);
            edge.setProperty("type", "aurelius");

            assertEquals(count(graph.query().edges()), 2);
            assertEquals(count(graph.query().limit(0).edges()), 0);
            assertEquals(count(graph.query().limit(1).edges()), 1);
            assertEquals(count(graph.query().limit(2).edges()), 2);
            assertEquals(count(graph.query().limit(3).edges()), 2);

            assertEquals(count(graph.query().has("type", "tinkerpop").has("type", "tinkerpop").edges()), 1);
            assertEquals(graph.query().has("type", "tinkerpop").edges().iterator().next().getProperty("weight"), 1.0);
            assertEquals(count(graph.query().has("type", "aurelius").edges()), 1);
            assertEquals(graph.query().has("type", "aurelius").edges().iterator().next().getPropertyKeys().size(), 1);
            assertEquals(count(graph.query().hasNot("weight").edges()), 1);
            assertEquals(graph.query().hasNot("weight").edges().iterator().next().getProperty("type"), "aurelius");

            assertEquals(count(graph.query().has("weight", 1.0).edges()), 1);
            assertEquals(graph.query().has("weight", 1.0).edges().iterator().next().getProperty("type"), "tinkerpop");
            assertEquals(count(graph.query().has("weight", 1.0).has("type", "tinkerpop").edges()), 1);
            assertEquals(graph.query().has("weight", 1.0).has("type", "tinkerpop").edges().iterator().next().getProperty("type"), "tinkerpop");
            assertEquals(count(graph.query().has("weight", 1.0).has("type", "aurelius").edges()), 0);

            assertEquals(graph.query().interval("weight", 0.0, 1.1).edges().iterator().next().getProperty("type"), "tinkerpop");
            assertEquals(count(graph.query().interval("weight", 0.0, 1.0).edges()), 0);
        }
        graph.shutdown();
    }

    public void testGraphQueryForHasOR() {
        Graph graph = graphTest.generateGraph();
        if (graph.getFeatures().supportsEdgeIndex && graph instanceof KeyIndexableGraph) {
            ((KeyIndexableGraph) graph).createKeyIndex("type", Edge.class);
        }
        if (graph.getFeatures().supportsEdgeProperties && graph.getFeatures().supportsVertexProperties) {
            Vertex marko = graph.addVertex(null);
            marko.setProperty("name", "marko");
            Vertex matthias = graph.addVertex(null);
            matthias.setProperty("name", "matthias");
            Vertex stephen = graph.addVertex(null);
            stephen.setProperty("name", "stephen");

            Edge edge = marko.addEdge("knows", stephen);
            edge.setProperty("type", "tinkerpop");
            edge.setProperty("weight", 1.0);
            edge = marko.addEdge("knows", matthias);
            edge.setProperty("type", "aurelius");

            assertEquals(count(graph.query().has("type", "tinkerpop", "aurelius").edges()), 2);
            assertEquals(count(graph.query().has("type", "tinkerpop", "aurelius").has("type", "tinkerpop").edges()), 1);
            assertEquals(count(graph.query().has("type", "tinkerpop", "aurelius").has("type", "tinkerpop").has("type", "aurelius").edges()), 0);

           // assertEquals(graph.query().has("type", "tinkerpop", "aurelius").edges().iterator().next().getProperty("weight"), 1.0);
{'fraction_non_alphanumeric': 0.18914720654481437, 'fraction_numerical': 0.015119349660850205, 'mean_word_length': 3.1146144013634425, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '832985', 'n_tokens_mistral': 5530, 'n_tokens_neox': 5272, 'n_words': 745}