当前位置: 首页>>代码示例>>C#>>正文


C# GraphNode.AddRelative方法代码示例

本文整理汇总了C#中GraphNode.AddRelative方法的典型用法代码示例。如果您正苦于以下问题:C# GraphNode.AddRelative方法的具体用法?C# GraphNode.AddRelative怎么用?C# GraphNode.AddRelative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphNode的用法示例。


在下文中一共展示了GraphNode.AddRelative方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Three_Nodes_In_Tree_Graph_Returns_Valid_Path_With_Length_Of_Two

        public void Three_Nodes_In_Tree_Graph_Returns_Valid_Path_With_Length_Of_Two()
        {
            var graphRoot = new GraphNode<int> { Value = 1 };
            var secondNode = new GraphNode<int> { Value = 2 };
            var thirdNode = new GraphNode<int> { Value = 3 };

            graphRoot.AddRelative(secondNode);
            graphRoot.AddRelative(thirdNode);

            var walker = new GraphWalker<int>(graphRoot);

            var walkingPath = walker.WalkToNode(3);

            Assert.AreEqual(true, walkingPath.IsValid);
            Assert.AreEqual(2, walkingPath.Path.Count, "Path length should be two (nodes) for three node tree graph");
        }
开发者ID:stephengodbold,项目名称:workitem-migrator,代码行数:16,代码来源:GraphWalkerTests.cs

示例2: Five_Nodes_In_A_Graph_Returns_Valid_Path_With_Length_Of_Three

        public void Five_Nodes_In_A_Graph_Returns_Valid_Path_With_Length_Of_Three()
        {
            var graphRoot = new GraphNode<int> { Value = 1 };
            var secondNode = new GraphNode<int> { Value = 2 };
            var thirdNode = new GraphNode<int> { Value = 3 };
            var fourthNode = new GraphNode<int> { Value = 4 };
            var fifthNode = new GraphNode<int> { Value = 5 };

            //first level
            graphRoot.AddRelative(secondNode);
            graphRoot.AddRelative(thirdNode);

            //second level
            thirdNode.AddRelative(fourthNode);
            secondNode.AddRelative(fifthNode);

            fourthNode.AddRelative(graphRoot);

            var walker = new GraphWalker<int>(graphRoot);
            var walkingPath = walker.WalkToNode(5);

            Assert.AreEqual(true, walkingPath.IsValid);
            Assert.AreEqual(3, walkingPath.Path.Count, "Path length should be three (nodes) for six node graph");
        }
开发者ID:stephengodbold,项目名称:workitem-migrator,代码行数:24,代码来源:GraphWalkerTests.cs

示例3: Two_Paths_To_Target_Returns_Shortest_Valid_Path

        public void Two_Paths_To_Target_Returns_Shortest_Valid_Path()
        {
            var graphRoot = new GraphNode<int> { Value = 1 };
            var secondNode = new GraphNode<int> { Value = 2 };
            var thirdNode = new GraphNode<int> { Value = 3 };
            var fourthNode = new GraphNode<int> { Value = 4 };
            var fifthNode = new GraphNode<int> { Value = 5 };

            graphRoot.AddRelative(secondNode);
            graphRoot.AddRelative(thirdNode);
            secondNode.AddRelative(fourthNode);
            thirdNode.AddRelative(fifthNode);
            fourthNode.AddRelative(fifthNode);

            var walker = new GraphWalker<int>(graphRoot);
            var walkingPath = walker.WalkToNode(5);

            Assert.AreEqual(true, walkingPath.IsValid);
            Assert.AreEqual(3, walkingPath.Path.Count, "Path length should be three (nodes) for five node graph");
        }
开发者ID:stephengodbold,项目名称:workitem-migrator,代码行数:20,代码来源:GraphWalkerTests.cs

示例4: Value_Not_In_Graph_Throws_Arg_Out_Of_Range

        public void Value_Not_In_Graph_Throws_Arg_Out_Of_Range()
        {
            var graphRoot = new GraphNode<int> { Value = 1 };
            var secondNode = new GraphNode<int> { Value = 2 };
            var thirdNode = new GraphNode<int> { Value = 3 };

            graphRoot.AddRelative(secondNode);
            graphRoot.AddRelative(thirdNode);

            var walker = new GraphWalker<int>(graphRoot);
            var exceptional = false;

            try
            {
                walker.WalkToNode(5);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                exceptional = true;
                Assert.AreEqual(5, ex.ActualValue);
                Assert.AreEqual("value", ex.ParamName);
            }

            Assert.IsTrue(exceptional, "Expected to catch an argument out of range exception");
        }
开发者ID:stephengodbold,项目名称:workitem-migrator,代码行数:25,代码来源:GraphWalkerTests.cs


注:本文中的GraphNode.AddRelative方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。