コード例 #1
0
        public void CanDFSCyclicGraphAsAdjacencyList()
        {
            var scanner = new Scanner(CreateStream(
                                          "3 3\n1 2\n1 3\n2 3"
                                          ));

            var g    = Graph.AsAdjacencyList(scanner, directed: false);
            var path = new List <int>();

            GraphTraversal.DFS(g, 0, (node) => path.Add(node));

            Assert.True(path.Count == 3);

            Assert.True(
                string.Join(",", path.Select(x => x.ToString())) ==
                "0,2,1"
                );
        }
コード例 #2
0
        public void CanBFSCyclicGraphAsVertexList()
        {
            var scanner = new Scanner(CreateStream(
                                          "3 3\n1 2\n1 3\n2 3"
                                          ));

            var g    = Graph.AsVertexList(scanner, directed: false);
            var path = new List <int>();

            GraphTraversal.BFS(g, g[0], (node) => path.Add(node.Index));

            Assert.True(path.Count == 3);

            Assert.True(
                string.Join(",", path.Select(x => x.ToString())) ==
                "0,1,2"
                );
        }
コード例 #3
0
        public void CanBFSAcyclicGraphAsAdjacencyList()
        {
            var scanner = new Scanner(CreateStream(
                                          "7 6\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n"
                                          ));

            var g    = Graph.AsAdjacencyList(scanner, directed: false);
            var path = new List <int>();

            GraphTraversal.BFS(g, 0, (node) => path.Add(node));

            Assert.True(path.Count == 7);

            Assert.True(
                string.Join(",", path.Select(x => x.ToString())) ==
                "0,1,2,3,4,5,6"
                );
        }
コード例 #4
0
ファイル: ProjectTest.cs プロジェクト: seanliu96/GraphView
        public void VerticesOutCreatedProjectABByNameByInCreatedCountOrderBySelectB()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = graphCommand.g().V().Out("created")
                                .Project("a", "b")
                                .By("name")
                                .By(GraphTraversal.__().In("created").Count())
                                .Order().By(
                    GraphTraversal.__().Select("b"),
                    GremlinKeyword.Order.Decr)
                                .Select("a");

                var result = traversal.Next();

                CheckUnOrderedResults(new [] { "lop", "lop", "lop", "ripple" }, result);
            }
        }
コード例 #5
0
        public void CanDFSAcyclicGraphAsVertexList()
        {
            var scanner = new Scanner(CreateStream(
                                          "7 6\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n"
                                          ));

            var g    = Graph.AsVertexList(scanner, directed: false);
            var path = new List <int>();

            GraphTraversal.DFS(g, g[0], (node) => path.Add(node.Index));

            Assert.True(path.Count == 7);

            Assert.True(
                string.Join(",", path.Select(x => x.ToString())) ==
                "0,2,6,5,1,4,3"
                );
        }
コード例 #6
0
        public void VerticesUntilOutOutRepeatInAsAInAsBSelectABByName()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                graphCommand.OutputFormat = OutputFormat.GraphSON;
                var traversal = graphCommand.g().V().Until(GraphTraversal.__().Out().Out()).Repeat(GraphTraversal.__().In().As("a").In().As("b")).Select("a", "b").By("name");

                var     result        = traversal.Next();
                dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault());

                Assert.AreEqual(2, dynamicResult.Count);
                foreach (var temp in dynamicResult)
                {
                    Assert.AreEqual("josh", temp["a"].ToString());
                    Assert.AreEqual("marko", temp["b"].ToString());
                }
            }
        }
コード例 #7
0
        internal override GremlinToSqlContext GetContext()
        {
            GremlinToSqlContext inputContext = GetInputContext();

            if (inputContext.PivotVariable == null)
            {
                throw new TranslationException("The PivotVariable of path()-step can't be null.");
            }

            if (ByList.Count == 0)
            {
                ByList.Add(GraphTraversal.__());
            }

            inputContext.PivotVariable.Path(inputContext, ByList, FromLabel, ToLabel);

            return(inputContext);
        }
コード例 #8
0
        /// <summary>
        /// Gets users by their identifier
        /// </summary>
        public static GraphTraversal <Vertex, Vertex> Users(this GraphTraversalSource g, string userId, params string[] additionalUserIds)
        {
            var userIds = new List <string>();

            userIds.Add(userId);
            userIds.AddRange(additionalUserIds);
            GraphTraversal <Vertex, Vertex> t = g.V().HasLabel(VertexUser);

            if (userIds.Count == 1)
            {
                t = t.Has(KeyUserId, userIds[0]);
            }
            else if (userIds.Count > 1)
            {
                t = t.Has(KeyUserId, P.Within(userIds.ToArray()));
            }
            return(t);
        }
コード例 #9
0
        protected override void Analyze(GraphTraversal graphTraversal, string graphTraversalPointer)
        {
            ValidateArrayIndex(
                graphTraversal.RunGraphIndex,
                Context.CurrentRun.Graphs,
                graphTraversalPointer,
                "graphTraversal",
                SarifPropertyName.RunGraphIndex,
                $"runs[{Context.CurrentRunIndex}].graphTraversals");

            ValidateArrayIndex(
                graphTraversal.ResultGraphIndex,
                Context.CurrentResult.Graphs,
                graphTraversalPointer,
                "graphTraversal",
                SarifPropertyName.ResultGraphIndex,
                $"runs[{Context.CurrentRunIndex}].results[{Context.CurrentResultIndex}].graphTraversals");
        }
コード例 #10
0
ファイル: RepeatTest.cs プロジェクト: seanliu96/GraphView
        public void VerticesRepeatBothTimes10AsAOutAsBSelectAB()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                graphCommand.OutputFormat = OutputFormat.GraphSON;
                var traversal = graphCommand.g().V().Repeat(GraphTraversal.__().Both()).Times(10).As("a").Out().As("b").Select("a", "b");

                int     counter = 0;
                dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next()[0]);
                foreach (var result in results)
                {
                    Assert.IsTrue(result["a"] != null);
                    Assert.IsTrue(result["b"] != null);
                    counter++;
                }
                Assert.IsTrue(counter == 43958);
            }
        }
コード例 #11
0
        /// <summary>
        /// Create VideoVertex
        /// </summary>
        public static GraphTraversal <Vertex, Vertex> CreateEdgeUploadedForUserAndVideo(
            this GraphTraversal <Vertex, Vertex> t, String userId)
        {
            return(t.SideEffect(
                       __.As("^" + VertexVideo).Coalesce <Vertex>(

                           __.In(EdgeUploaded)
                           .HasLabel(VertexUser)
                           .Has(PropertyUserId, userId),

                           __.V()
                           .Has(VertexUser, PropertyUserId, userId)
                           .AddE(EdgeUploaded)
                           .To("^" + VertexVideo)
                           .InV()
                           )
                       ));
        }
コード例 #12
0
        internal override GremlinToSqlContext GetContext()
        {
            GremlinToSqlContext inputContext = GetInputContext();

            if (inputContext.PivotVariable == null)
            {
                throw new TranslationException("The PivotVariable of select()-step can't be null.");
            }

            if (ByList.Count == 0)
            {
                ByList.Add(GraphTraversal.__());
            }

            inputContext.PivotVariable.Select(inputContext, Pop, SelectKeys, ByList);

            return(inputContext);
        }
コード例 #13
0
        /// <summary>
        /// Gets movies by their title.
        /// </summary>
        public static GraphTraversal <Vertex, Vertex> Movies(this GraphTraversalSource g, string title, params string[] additionalTitles)
        {
            var titles = new List <string>();

            titles.Add(title);
            titles.AddRange(additionalTitles);
            GraphTraversal <Vertex, Vertex> t = g.V().HasLabel(VertexMovie);

            if (titles.Count == 1)
            {
                t = t.Has(KeyTitle, titles[0]);
            }
            else if (titles.Count > 1)
            {
                t = t.Has(KeyTitle, P.Within(titles.ToArray()));
            }
            return(t);
        }
コード例 #14
0
        private void btnCompress_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text == string.Empty)
            {
                MessageBox.Show("Please enter Content");
                return;
            }

            _huffmannEncodedMap.Clear();
            var uniqueMap = _contentHandler.GetUniqueCharacterToFrequencyMapSortedByFreqInDescOrder(textBox1.Text);

            var result = _graphCreator.CreateGraph(uniqueMap);

            if (result)
            {
                var graph = _graphCreator.GetCreatedGraph();

                IGraphTraversal graphTraversal = new GraphTraversal();
                var             dictionary     = graphTraversal.GetHuffmannEncodingForCharacters(graph);

                foreach (var item in dictionary)
                {
                    _huffmannEncodedMap.Add(new DisplayData {
                        Key = item.Key.ToString(), Value = item.Value
                    });
                }
                listViewEncoding.DataContext = _huffmannEncodedMap;


                //get encoded bit data
                string message  = string.Empty;
                var    charList = textBox1.Text.ToCharArray().ToList();
                foreach (var item in charList)
                {
                    message += dictionary[item];
                }



                txbHuffmannCode.DataContext = new DisplayData {
                    Key = message
                };
            }
        }
コード例 #15
0
ファイル: WhereTest.cs プロジェクト: seanliu96/GraphView
        public void VerticesAsAOutCreatedAsBInCreatedAsCBothKnowsBothKnowsAsDWhereCNotEqAOrEqDSelectABCD()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                graphCommand.OutputFormat = OutputFormat.GraphSON;

                var traversal = graphCommand.g().V().As("a")
                                .Out("created").As("b")
                                .In("created").As("c")
                                .Both("knows").Both("knows").As("d")
                                .Where(
                    GraphTraversal.__().Where("c", Predicate.not(Predicate.eq("a")))
                    .And()
                    .Where("c", Predicate.not(Predicate.eq("d"))))
                                .Select("a", "b", "c", "d");

                var     result        = traversal.Next();
                dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault());

                Assert.AreEqual(2, dynamicResult.Count);
                List <string> ans = new List <string>();
                foreach (var temp in dynamicResult)
                {
                    ans.Add("a," + temp["a"]["id"].ToString()
                            + ";b," + temp["b"]["id"].ToString()
                            + ";c," + temp["c"]["id"].ToString()
                            + ";d," + temp["d"]["id"].ToString());
                }
                var markoId = ConvertToVertexId(graphCommand, "marko");
                var joshId  = ConvertToVertexId(graphCommand, "josh");
                var lopId   = ConvertToVertexId(graphCommand, "lop");
                var vadasId = ConvertToVertexId(graphCommand, "vadas");
                var peterId = ConvertToVertexId(graphCommand, "peter");

                List <string> expected = new List <string>
                {
                    "a," + markoId + ";b," + lopId + ";c," + joshId + ";d," + vadasId,
                    "a," + peterId + ";b," + lopId + ";c," + joshId + ";d," + vadasId
                };

                CheckUnOrderedResults(expected, ans);
            }
        }
コード例 #16
0
ファイル: WhereTest.cs プロジェクト: seanliu96/GraphView
        public void HasVextexIdAsAOutCreatedInCreatedAsBWhereAsBOutCreatedHasNameRippleValuesAgeName()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                string markoVertexId = this.ConvertToVertexId(graphCommand, "marko");

                // Skipping this validation until we can fix the bugs.

                var traversal = graphCommand.g().V().HasId(markoVertexId).As("a")
                                .Out("created").In("created").As("b")
                                .Where(GraphTraversal.__().As("b").Out("created").Has("name", "ripple"))
                                .Values("age", "name");

                var result = traversal.Next();
                CheckUnOrderedResults(new List <string> {
                    "josh", "32"
                }, result);
            }
        }
コード例 #17
0
        public void ChooseIfPersonThenUnionOutLangOutAndOutNameElseInLabel()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = GraphViewCommand.g().V().Choose(
                    GraphTraversal.__().Label().Is("person"),
                    GraphTraversal.__().Union(
                        GraphTraversal.__().Out().Values("lang"),
                        GraphTraversal.__().Out().Values("name")),
                    GraphTraversal.__().In().Label());

                var result         = traversal.Next();
                var expectedResult = new List <string>()
                {
                    "lop", "lop", "lop", "ripple", "java", "java", "java", "java", "josh", "vadas", "person", "person", "person", "person"
                };
                AbstractGremlinTest.CheckUnOrderedResults <string>(expectedResult, result);
            }
        }
コード例 #18
0
        private void Visit(GraphTraversal graphTraversal, string graphTraversalPointer)
        {
            Analyze(graphTraversal, graphTraversalPointer);

            if (graphTraversal.Description != null)
            {
                Visit(graphTraversal.Description, graphTraversalPointer.AtProperty(SarifPropertyName.Description));
            }

            if (graphTraversal.EdgeTraversals != null)
            {
                string edgeTraversalsPointer = graphTraversalPointer.AtProperty(SarifPropertyName.EdgeTraversals);

                for (int i = 0; i < graphTraversal.EdgeTraversals.Count; ++i)
                {
                    Visit(graphTraversal.EdgeTraversals[i], edgeTraversalsPointer.AtIndex(i));
                }
            }
        }
コード例 #19
0
ファイル: CoalesceTest.cs プロジェクト: seanliu96/GraphView
        public void CoalesceWithGroupCount()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                GraphViewCommand.OutputFormat = OutputFormat.GraphSON;
                var traversal = GraphViewCommand.g().V()
                                .Coalesce(
                    GraphTraversal.__().Out("likes"),
                    GraphTraversal.__().Out("knows"),
                    GraphTraversal.__().Out("created"))
                                .GroupCount()
                                .By("name");

                var result = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault());
                Assert.AreEqual(1, (int)result[0]["josh"]);
                Assert.AreEqual(2, (int)result[0]["lop"]);
                Assert.AreEqual(1, (int)result[0]["ripple"]);
                Assert.AreEqual(1, (int)result[0]["vadas"]);
            }
        }
コード例 #20
0
        public void DedupInsideBy()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                GraphViewCommand.OutputFormat = OutputFormat.GraphSON;
                var traversal = GraphViewCommand.g().V()
                                .Group()
                                .By("label")
                                .By(GraphTraversal.__().BothE()
                                    .Values("weight")
                                    .Dedup()
                                    .Fold());

                dynamic result = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault());

                Assert.AreEqual(1, result.Count);
                CheckUnOrderedResults(new double[] { 0.2, 0.4, 1.0 }, ((JArray)result[0]["software"]).Select(p => (double)p).ToList());
                CheckUnOrderedResults(new double[] { 0.2, 0.4, 0.5, 1.0 }, ((JArray)result[0]["person"]).Select(p => (double)p).ToList());
            }
        }
コード例 #21
0
        public void HasVId1VId2LocalUnionOutECountInECountOutEWeightSum()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                GraphViewCommand.OutputFormat = OutputFormat.GraphSON;
                string vertexId1 = this.ConvertToVertexId(GraphViewCommand, "marko");
                string vertexId2 = this.ConvertToVertexId(GraphViewCommand, "vadas");

                var traversal = GraphViewCommand.g().V(vertexId1, vertexId2)
                                .Local(
                    GraphTraversal.__().Union(
                        GraphTraversal.__().OutE().Count(),
                        GraphTraversal.__().InE().Count(),
                        GraphTraversal.__().OutE().Values("weight").Sum()));
                dynamic result = JsonConvert.DeserializeObject <dynamic>(traversal.FirstOrDefault());

                // Assertions missing, revisit this once we actually get the above traversal to work.
                CheckUnOrderedResults(new double[] { 0d, 0d, 0d, 3d, 1d, 1.9d }, ((JArray)result).Select(j => j.ToObject <double>()).ToList());
            }
        }
コード例 #22
0
ファイル: LocalTest.cs プロジェクト: seanliu96/GraphView
        public void VertexWithIdLocalBothECreatedLimit1()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                string joshVertexId = this.ConvertToVertexId(graphCommand, "josh");

                graphCommand.OutputFormat = OutputFormat.GraphSON;
                var traversal = graphCommand.g().V(joshVertexId).Local(GraphTraversal.__().BothE("created").Limit(1));

                var     result        = traversal.Next();
                dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault());

                Assert.AreEqual(1, dynamicResult.Count);

                var edge = dynamicResult[0];
                Assert.AreEqual("created", edge["label"].ToString());
                double edgeWeight = double.Parse(edge["properties"]["weight"].ToString());
                Assert.IsTrue(edgeWeight.Equals(1.0D) || edgeWeight.Equals(0.4D));
            }
        }
コード例 #23
0
        public void HasVertexIdUnionOutAndOutRepeatTimes2()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                string vertexId = this.ConvertToVertexId(GraphViewCommand, "marko");

                var traversal = GraphViewCommand.g().V().HasId(vertexId)
                                .Union(
                    GraphTraversal.__().Repeat(GraphTraversal.__().Out()).Times(2),
                    GraphTraversal.__().Out())
                                .Values("name");

                var result         = traversal.Next();
                var expectedResult = new List <string>()
                {
                    "lop", "lop", "ripple", "josh", "vadas"
                };
                AbstractGremlinTest.CheckUnOrderedResults <string>(expectedResult, result);
            }
        }
コード例 #24
0
ファイル: IOTQueryTest.cs プロジェクト: seanliu96/GraphView
        public void ProjectTest2()
        {
            GraphViewConnection connection = new GraphViewConnection("https://graphview.documents.azure.com:443/",
                                                                     "MqQnw4xFu7zEiPSD+4lLKRBQEaQHZcKsjlHxXn2b96pE/XlJ8oePGhjnOofj1eLpUdsfYgEhzhejk2rjH/+EKA==",
                                                                     "GroupMatch", "MarvelTest", GraphType.GraphAPIOnly, AbstractGremlinTest.TEST_USE_REVERSE_EDGE, 1, AbstractGremlinTest.TEST_PARTITION_BY_KEY);
            GraphViewCommand graph = new GraphViewCommand(connection);
            //var results = graph.g().V().Project("c").By("name").Where("c", Predicate.eq("josh"));
            // (0) check the has
            //var results = graph.g().V().Has("name", Predicate.eq("josh")).Values("name");
            // (1) first step, ref the origin
            var results = graph.g().V().Project("c").By("name").Where(GraphTraversal.__().V().Has("c", Predicate.eq("josh")));

            // (2) second step, ref the new alias
            // var results = graph.g().V().Project("c").By("name").Where(GraphTraversal.__().Values("c").Is("josh"));

            foreach (var result in results)
            {
                Console.WriteLine(result);
            }
        }
コード例 #25
0
ファイル: LazyCommitTest.cs プロジェクト: seanliu96/GraphView
        public void Test_Lazy_AddProperty()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                var traversal = command.g().V().Has("name", "marko").Union(
                    GraphTraversal.__().Property("city", "beijing").Property("age", "20").Commit().ValueMap(),
                    GraphTraversal.__().OutE("created").Property("number", "10").ValueMap()).Commit();
                var result = traversal.Next();
                Assert.IsTrue(result.Count == 2);
                Assert.IsTrue(result[0].Contains("name:[marko]"));
                Assert.IsTrue(result[0].Contains("age:[20]"));
                Assert.IsTrue(result[0].Contains("city:[beijing]"));
                Assert.IsTrue(result[1].Contains("weight:0.4"));
                Assert.IsTrue(result[1].Contains("number:10"));

                foreach (var r in result)
                {
                    Console.WriteLine(r);
                }
            }
        }
コード例 #26
0
        public void DedupByAnonymousTraversal()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = GraphViewCommand.g().V()
                                .Both()
                                .Both()
                                .Dedup()
                                .By(GraphTraversal.__()
                                    .OutE()
                                    .Count())
                                .Values("name");
                var result = traversal.Next();

                Assert.AreEqual(4, result.Count());
                Assert.IsTrue(result.Contains("josh"));
                Assert.IsTrue(result.Contains("peter"));
                Assert.IsTrue(result.Contains("marko"));
                Assert.IsTrue(result.Contains("vadas") || result.Contains("ripple") || result.Contains("lop"));
            }
        }
コード例 #27
0
ファイル: UnfoldTest.cs プロジェクト: seanliu96/GraphView
        public void LocalOutEFoldUnfold()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                graphCommand.OutputFormat = OutputFormat.GraphSON;

                var traversal = graphCommand.g().V().Local(GraphTraversal.__().OutE().Fold()).Unfold();

                var              result        = traversal.Next();
                dynamic          dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault());
                HashSet <string> edgeIds       = new HashSet <string>();

                foreach (var res in dynamicResult)
                {
                    edgeIds.Add(string.Format("{0}_{1}", res["inV"].ToString(), res["id"].ToString()));
                }

                Assert.AreEqual(6, dynamicResult.Count);
                Assert.AreEqual(6, edgeIds.Count);
            }
        }
コード例 #28
0
ファイル: RepeatTest.cs プロジェクト: seanliu96/GraphView
        public void VerticesRepeatOutTimes2EmitPath()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                graphCommand.OutputFormat = OutputFormat.GraphSON;
                var traversal = graphCommand.g().V().Repeat(GraphTraversal.__().Out()).Times(2).Emit().Path();

                dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next()[0]);
                Dictionary <int, long> pathLengths = new Dictionary <int, long>();
                foreach (dynamic path in results)
                {
                    long count;
                    pathLengths.TryGetValue(path["objects"].Count, out count);
                    pathLengths[path["objects"].Count] = count + 1;
                }
                Assert.AreEqual(2, pathLengths.Count);
                Assert.AreEqual(8, results.Count);
                Assert.AreEqual(6, pathLengths[2]);
                Assert.AreEqual(2, pathLengths[3]);
            }
        }
コード例 #29
0
        public void HasLabelPersonAsPMapBothELabelGroupCountAsRSelectPR()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                graphCommand.OutputFormat = OutputFormat.GraphSON;
                var traversal = graphCommand.g().V()
                                .HasLabel("person").As("p")
                                .Map(GraphTraversal.__().BothE().Label().GroupCount()).As("r").Select("p", "r");

                var     results       = traversal.Next();
                dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(results.FirstOrDefault());

                Assert.AreEqual(4, dynamicResult.Count);
                foreach (var result in dynamicResult)
                {
                    if ((string)result.p.id == ConvertToVertexId(graphCommand, "marko"))
                    {
                        Assert.AreEqual(1, (int)result.r["created"]);
                        Assert.AreEqual(2, (int)result.r["knows"]);
                    }
                    else if ((string)result.p.id == ConvertToVertexId(graphCommand, "vadas"))
                    {
                        Assert.AreEqual(1, (int)result.r["knows"]);
                    }
                    else if ((string)result.p.id == ConvertToVertexId(graphCommand, "josh"))
                    {
                        Assert.AreEqual(2, (int)result.r["created"]);
                        Assert.AreEqual(1, (int)result.r["knows"]);
                    }
                    else if ((string)result.p.id == ConvertToVertexId(graphCommand, "peter"))
                    {
                        Assert.AreEqual(1, (int)result.r["created"]);
                    }
                    else
                    {
                        Assert.Fail("Unknown vertex result");
                    }
                }
            }
        }
コード例 #30
0
ファイル: PathTest.cs プロジェクト: seanliu96/GraphView
        public void get_g_V_out_out_path_byXnameX_byXageX()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                graphCommand.OutputFormat = OutputFormat.GraphSON;

                GraphTraversal traversal =
                    graphCommand.g().V().Out().Out().Path().By("name").By("age");

                dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault());

                Assert.AreEqual(2, results.Count);

                int counter = 0;
                foreach (dynamic result in results)
                {
                    List <object> actualList = new List <object>();
                    actualList.Add((string)result["objects"][0]);
                    actualList.Add((int)result["objects"][1]);
                    actualList.Add((string)result["objects"][2]);

                    if (actualList.Last().Equals("ripple"))
                    {
                        CheckPathResults(new List <object> {
                            "marko", 32, "ripple"
                        }, actualList);
                        counter++;
                    }
                    else
                    {
                        CheckPathResults(new List <object> {
                            "marko", 32, "lop"
                        }, actualList);
                        counter++;
                    }
                }

                Assert.AreEqual(2, counter);
            }
        }