public void TestThatGraphCanBeCreatedWithTwoConnectedNodes() { var root = new SimpleNode("root"); root.AddChild(new SimpleNode("child")); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); Assert.AreEqual(2, graph.Order); }
public void TestAddedNodeIsReturnedInChildEnumeration() { var child = new SimpleNode("child"); var sn1 = new SimpleNode("test"); sn1.AddChild(child); CollectionAssert.Contains(new List<SimpleNode>(sn1.GetChildren()), child); }
public void TestThatNodeTailsAreReachableThroughEnumeration() { var root = new SimpleNode("root"); var child = new SimpleNode("child"); root.AddChild(child); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); CollectionAssert.Contains(new List<SimpleNode>(graph.TailsFor(child)), root); }
public void TestThatBuilderHandlesCycle() { var root = new SimpleNode("root"); var child = new SimpleNode("child"); root.AddChild(child); child.AddChild(root); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); Assert.AreEqual(2, graph.Order); }
public void TestThatHeadsForRootWithTwoEdgesToChildIncludesChildTwice() { var root = new SimpleNode("root"); var child = new SimpleNode("child"); root.AddChild(child); root.AddChild(child); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); Assert.AreEqual(2, graph.HeadsFor(root).Count()); }
public void TestThatGraphCanBeWalkedFromRoot() { var root = new SimpleNode("root"); var child = new SimpleNode("child"); root.AddChild(child); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); var result = graph.Walk().Aggregate("", (str, node) => str + node.ToString()); Assert.AreEqual("rootchild", result); }
public void TestThatHeadsAreOrderedBasedOnInput() { var root = new SimpleNode("root"); var child1 = new SimpleNode("child1"); var child2 = new SimpleNode("child2"); root.AddChild(child1); root.AddChild(child2); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); Assert.AreSame(child1, graph.HeadByIndex(root, 0)); }
public void ThatThatThereIsSinglePathBetweenNodeAndItself() { var root = new SimpleNode("root"); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); var paths = graph.FindPaths(root, root); Assert.AreEqual("root", DescribePaths(paths)); }
public void ThatThatPathBetweenNodeAndChildContainsNodeAndChild() { var root = new SimpleNode("root"); var child = new SimpleNode("child"); root.AddChild(child); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); var paths = graph.FindPaths(root, child); Assert.AreEqual("root child", DescribePaths(paths)); }
public void TestThatWalkingIsDepthFirst() { var root = new SimpleNode("root"); var child11 = new SimpleNode("child11"); var child12 = new SimpleNode("child12"); var child111 = new SimpleNode("child111"); root.AddChild(child11); root.AddChild(child12); child11.AddChild(child111); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); var result = graph.Walk().Aggregate("", (str, node) => str + node.ToString()); Assert.AreEqual("rootchild11child111child12", result); }
public void TestThatTwoPathsAreFoundInDiamondGraph() { var root = new SimpleNode("root"); var child1 = new SimpleNode("child1"); var child2 = new SimpleNode("child2"); var end = new SimpleNode("end"); root.AddChild(child1); root.AddChild(child2); child1.AddChild(end); child2.AddChild(end); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); var paths = graph.FindPaths(root, end); Assert.AreEqual("root child1 end\nroot child2 end", DescribePaths(paths)); }
public void TestNodesWithSameValueHaveSameHashCode() { var sn1 = new SimpleNode("test"); var sn2 = new SimpleNode("test"); Assert.AreEqual(sn1.GetHashCode(), sn2.GetHashCode()); }
public void TestNodeHasValue() { var sn = new SimpleNode("test"); Assert.AreEqual("test", sn.Value); }
public void AddChild(SimpleNode child) { _children.Add(child); }
public void TestThatRootHasOutDegree() { var root = new SimpleNode("root"); var child = new SimpleNode("child"); root.AddChild(child); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); Assert.AreEqual(1, graph.OutDegreeOf(root)); }
public void TestNodesWithDifferentValuesAreNotEqual() { var sn1 = new SimpleNode("test"); var sn2 = new SimpleNode("test2"); Assert.AreNotEqual(sn1, sn2); }
public void TestNodesWithDifferentValuesHaveDifferentHashCodes() { var sn1 = new SimpleNode("test"); var sn2 = new SimpleNode("test2"); Assert.AreNotEqual(sn1.GetHashCode(), sn2.GetHashCode()); }
public void TestNodeToStringIsValue() { var sn = new SimpleNode("test"); Assert.AreEqual("test", sn.ToString()); }
private static IEnumerable<SimpleNode> GetChildren(SimpleNode node) { return node.GetChildren(); }
public void TestChildListIsInitiallyEmpty() { var sn1 = new SimpleNode("test"); Assert.AreEqual(0, sn1.GetChildren().Count()); }
public void TestThatGraphExposesRootNode() { var root = new SimpleNode("root"); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); Assert.AreSame(root, graph.Root); }
public void TestThatTwoPathsAreFoundForTwoEdgesBetweenVertices() { var root = new SimpleNode("root"); var child = new SimpleNode("child"); root.AddChild(child); root.AddChild(child); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); var paths = graph.FindPaths(root, child); Assert.AreEqual("root child\nroot child", DescribePaths(paths)); }
public void TestThatRootHeadsAreReachableThroughIndex() { var root = new SimpleNode("root"); var child = new SimpleNode("child"); root.AddChild(child); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); Assert.AreSame(child, graph.HeadByIndex(root, 0)); }
public void TestNodesWithSameValueAreEqual() { var sn1 = new SimpleNode("test"); var sn2 = new SimpleNode("test"); Assert.AreEqual(sn1, sn2); }
public void TestThatPathsCanBeFoundWhenThereIsACycle() { var root = new SimpleNode("root"); var child = new SimpleNode("child"); var target = new SimpleNode("target"); var back = new SimpleNode("back"); root.AddChild(child); child.AddChild(target); child.AddChild(back); back.AddChild(root); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); var paths = graph.FindPaths(root, target); var result = string.Join("|", paths.Select(path => string.Join(",", path))); Assert.AreEqual("root,child,target|root,child,back,root,child,target", result); }
public void TestThatTailsForChildWithTwoEdgesToRootIncludesRootTwice() { var root = new SimpleNode("root"); var child = new SimpleNode("child"); root.AddChild(child); root.AddChild(child); var graph = new GraphBuilder<SimpleNode>(GetChildren).Build(root); Assert.AreEqual(2, graph.TailsFor(child).Count()); }