本文整理汇总了C#中GraphNode.Add方法的典型用法代码示例。如果您正苦于以下问题:C# GraphNode.Add方法的具体用法?C# GraphNode.Add怎么用?C# GraphNode.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphNode
的用法示例。
在下文中一共展示了GraphNode.Add方法的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.Add(secondNode);
graphRoot.Add(thirdNode);
var walker = new GraphWalker<int>(graphRoot);
var path = walker.TraverseTo(3);
Assert.AreEqual(true, path.IsValid);
Assert.AreEqual(2, path.Count(), "Path length should be two (nodes) for three node tree graph");
}
示例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.Add(secondNode);
graphRoot.Add(thirdNode);
//second level
thirdNode.Add(fourthNode);
secondNode.Add(fifthNode);
fourthNode.Add(graphRoot);
var walker = new GraphWalker<int>(graphRoot);
var path = walker.TraverseTo(5);
Assert.AreEqual(true, path.IsValid);
Assert.AreEqual(3, path.Count(), "Path length should be three (nodes) for six node graph");
}
示例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.Add(secondNode);
graphRoot.Add(thirdNode);
secondNode.Add(fourthNode);
thirdNode.Add(fifthNode);
fourthNode.Add(fifthNode);
var walker = new GraphWalker<int>(graphRoot);
var path = walker.TraverseTo(5);
Assert.AreEqual(true, path.IsValid);
Assert.AreEqual(3, path.Count(), "Path length should be three (nodes) for five node graph");
}
示例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.Add(secondNode);
graphRoot.Add(thirdNode);
var walker = new GraphWalker<int>(graphRoot);
var exceptional = false;
try
{
walker.TraverseTo(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");
}