<commit_before>package com.tinkerpop.gremlin.functions.g.graph;

import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Element;
import com.tinkerpop.blueprints.pgm.Graph;
import com.tinkerpop.blueprints.pgm.Vertex;
import com.tinkerpop.blueprints.pgm.impls.tg.TinkerGraph;
import com.tinkerpop.blueprints.pgm.impls.tg.TinkerGraphFactory;
import com.tinkerpop.gremlin.BaseTest;
import com.tinkerpop.gremlin.compiler.context.GremlinScriptContext;
import com.tinkerpop.gremlin.compiler.types.Atom;
import com.tinkerpop.gremlin.compiler.util.Tokens;
import com.tinkerpop.gremlin.functions.Function;

import javax.script.ScriptContext;

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

    public void testCopyVertexEdgeUsingId() {
        Graph fromGraph = TinkerGraphFactory.createTinkerGraph();
        Graph toGraph = new TinkerGraph();
        GremlinScriptContext context = new GremlinScriptContext();
        context.getBindings(ScriptContext.ENGINE_SCOPE).put(Tokens.GRAPH_VARIABLE, new Atom<Graph>(fromGraph));

        Vertex v1 = fromGraph.getVertex(1);
        Function<Element> function = new CopyVertexEdgeFunction();
        function.compute(createUnaryArgs(toGraph, v1), context);

        Vertex v2 = toGraph.getVertex(1);
        for (String key : v1.getPropertyKeys()) {
            assertEquals(v2.getProperty(key), v1.getProperty(key));
        }

        Edge e1 = fromGraph.getEdge(8);
        function.compute(createUnaryArgs(toGraph, e1), context);

        Edge e2 = toGraph.getEdge(8);
        for (String key : e1.getPropertyKeys()) {
            assertEquals(e2.getProperty(key), e1.getProperty(key));
        }

        assertEquals(count(toGraph.getVertices()), 2);
        assertEquals(count(toGraph.getEdges()), 1);

    }

    public void testCopyVertexEdgeUsingName() {
        Graph fromGraph = TinkerGraphFactory.createTinkerGraph();
        Graph toGraph = new TinkerGraph();
        GremlinScriptContext context = new GremlinScriptContext();
        context.getBindings(ScriptContext.ENGINE_SCOPE).put(Tokens.GRAPH_VARIABLE, new Atom<Graph>(fromGraph));

        Vertex v1 = fromGraph.getVertex(1);
        Function<Element> function = new CopyVertexEdgeFunction();
        function.compute(createUnaryArgs(toGraph, v1, "vertices", "name"), context);

        Vertex v2 = toGraph.getVertex(1);
        for (String key : v1.getPropertyKeys()) {
            assertEquals(v2.getProperty(key), v1.getProperty(key));
        }

        Edge e1 = fromGraph.getEdge(8);
        function.compute(createUnaryArgs(toGraph, e1, "vertices", "name"), context);

        Edge e2 = toGraph.getEdge(8);
        for (String key : e1.getPropertyKeys()) {
            assertEquals(e2.getProperty(key), e1.getProperty(key));
        }

        assertEquals(count(toGraph.getVertices()), 2);
        assertEquals(count(toGraph.getEdges()), 1);

    }

    public void testCopyVertexUsingDoublePropertiesToThrowException() {
        Graph fromGraph = TinkerGraphFactory.createTinkerGraph();
        Graph toGraph = new TinkerGraph();
        GremlinScriptContext context = new GremlinScriptContext();
        context.getBindings(ScriptContext.ENGINE_SCOPE).put(Tokens.GRAPH_VARIABLE, new Atom<Graph>(fromGraph));

        Vertex v1 = fromGraph.getVertex(3);
        Function<Element> function = new CopyVertexEdgeFunction();
        function.compute(createUnaryArgs(toGraph, v1, "vertices", "lang"), context);

        v1 = fromGraph.getVertex(5);
        function = new CopyVertexEdgeFunction();<commit_msg>more test cases for CopyVertexEdgeFunction. In particular, making sure that the element returned is one copied over.<commit_after>package com.tinkerpop.gremlin.functions.g.graph;

import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Element;
import com.tinkerpop.blueprints.pgm.Graph;
import com.tinkerpop.blueprints.pgm.Vertex;
import com.tinkerpop.blueprints.pgm.impls.tg.TinkerGraph;
import com.tinkerpop.blueprints.pgm.impls.tg.TinkerGraphFactory;
import com.tinkerpop.gremlin.BaseTest;
import com.tinkerpop.gremlin.compiler.context.GremlinScriptContext;
import com.tinkerpop.gremlin.compiler.types.Atom;
import com.tinkerpop.gremlin.compiler.util.Tokens;
import com.tinkerpop.gremlin.functions.Function;

import javax.script.ScriptContext;

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

    public void testCopyVertexEdgeUsingId() {
        Graph fromGraph = TinkerGraphFactory.createTinkerGraph();
        Graph toGraph = new TinkerGraph();
        GremlinScriptContext context = new GremlinScriptContext();
        context.getBindings(ScriptContext.ENGINE_SCOPE).put(Tokens.GRAPH_VARIABLE, new Atom<Graph>(fromGraph));

        Vertex v1 = fromGraph.getVertex(1);
        Function<Element> function = new CopyVertexEdgeFunction();
        Element element = function.compute(createUnaryArgs(toGraph, v1), context).getValue();

        Vertex v2 = toGraph.getVertex(1);
        assertEquals(element, v2);
        for (String key : v1.getPropertyKeys()) {
            assertEquals(v2.getProperty(key), v1.getProperty(key));
            assertEquals(v2.getProperty(key), element.getProperty(key));
        }

        Edge e1 = fromGraph.getEdge(8);
        element = function.compute(createUnaryArgs(toGraph, e1), context).getValue();

        Edge e2 = toGraph.getEdge(8);
        assertEquals(element, e2);
        for (String key : e1.getPropertyKeys()) {
            assertEquals(e2.getProperty(key), e1.getProperty(key));
            assertEquals(e2.getProperty(key), element.getProperty(key));
        }

        assertEquals(count(toGraph.getVertices()), 2);
        assertEquals(count(toGraph.getEdges()), 1);

    }

    public void testCopyVertexEdgeUsingName() {
        Graph fromGraph = TinkerGraphFactory.createTinkerGraph();
        Graph toGraph = new TinkerGraph();
        GremlinScriptContext context = new GremlinScriptContext();
        context.getBindings(ScriptContext.ENGINE_SCOPE).put(Tokens.GRAPH_VARIABLE, new Atom<Graph>(fromGraph));

        Vertex v1 = fromGraph.getVertex(1);
        Function<Element> function = new CopyVertexEdgeFunction();
        Element element = function.compute(createUnaryArgs(toGraph, v1, "vertices", "name"), context).getValue();

        Vertex v2 = toGraph.getVertex(1);
        assertEquals(element, v2);
        for (String key : v1.getPropertyKeys()) {
            assertEquals(v2.getProperty(key), v1.getProperty(key));
            assertEquals(v2.getProperty(key), element.getProperty(key));
        }

        Edge e1 = fromGraph.getEdge(8);
        element = function.compute(createUnaryArgs(toGraph, e1, "vertices", "name"), context).getValue();

        Edge e2 = toGraph.getEdge(8);
        assertEquals(element, e2);
        for (String key : e1.getPropertyKeys()) {
            assertEquals(e2.getProperty(key), e1.getProperty(key));
            assertEquals(e2.getProperty(key), element.getProperty(key));
        }

        assertEquals(count(toGraph.getVertices()), 2);
        assertEquals(count(toGraph.getEdges()), 1);

    }

    public void testCopyVertexUsingDoublePropertiesToThrowException() {
        Graph fromGraph = TinkerGraphFactory.createTinkerGraph();
        Graph toGraph = new TinkerGraph();
        GremlinScriptContext context = new GremlinScriptContext();
        context.getBindings(ScriptContext.ENGINE_SCOPE).put(Tokens.GRAPH_VARIABLE, new Atom<Graph>(fromGraph));

        Vertex v1 = fromGraph.getVertex(3);
        Function<Element> function = new CopyVertexEdgeFunction();
        function.compute(createUnaryArgs(toGraph, v1, "vertices", "lang"), context);

        v1 = fromGraph.getVertex(5);
        function = new CopyVertexEdgeFunction();
{'fraction_non_alphanumeric': 0.11626130141347256, 'fraction_numerical': 0.011460588310199924, 'mean_word_length': 3.7001795332136447, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '5400035', 'n_tokens_mistral': 2390, 'n_tokens_neox': 2285, 'n_words': 401}