public void Test_10_Navigation() { DataStructures.GenericNode <string> root = new DataStructures.GenericNode <string>(); GenericNodeTestData.AddTestChildren(root); GenericNodeTestData.AssertTestChildren(root); return; }
//-------------------------------------------------------------------- private void _AssertCountingVisitor(DataStructures.GenericNode <string> Node, DataStructures.VisitationType VisitType, int ExpectedCount) { //Console.WriteLine( "Testing VisitNodes( " + VisitType.ToString() + " )." ); DataStructures.StringNode.CountingVisitor visitor = new DataStructures.StringNode.CountingVisitor(); Node.VisitNodes(visitor, VisitType); Assert.AreEqual(ExpectedCount, visitor.Count, "Visitor count mismatch after VisitNodes( " + VisitType.ToString() + " )."); }
public void Test_00_TextGraph() { DataStructures.GenericNode <string> root = new DataStructures.GenericNode <string>(); GenericNodeTestData.AddTestChildren(root); Console.WriteLine(root.TextGraph()); return; }
void DataStructures.GenericNode <string> .INodeNotificationListener.Notify(DataStructures.GenericNode <string> .NodeNotification Notification_in) { string text = ""; if (Notification_in is DataStructures.GenericNode <string> .NodeUpdateNotification) { text += "NodeUpdateNotification"; } else if (Notification_in is DataStructures.GenericNode <string> .NodeClearChildrenNotification) { text += "NodeClearChildrenNotification"; } else if (Notification_in is DataStructures.GenericNode <string> .NodeChildNotification) { text += "NodeChildNotification"; } else if (Notification_in is DataStructures.GenericNode <string> .NodeAddChildNotification) { text += "NodeAddChildNotification"; } else if (Notification_in is DataStructures.GenericNode <string> .NodeRemoveChildNotification) { text += "NodeRemoveChildNotification"; } else if (Notification_in is DataStructures.GenericNode <string> .NodeNotification) { text += "NodeNotification"; } text += "; " + Notification_in.Status; text += "; " + Notification_in.Node.Value; System.Diagnostics.Debug.Print(text); return; }
//-------------------------------------------------------------------- public static void AddTestChildren(DataStructures.GenericNode <string> root) { // D3 = C2.Prev A1 // C3 = C2.Next +- B1 // A1 = C1.First | +- C1 // C7 = C1.Last | | +- D1 // A1 = C1.Root | | +- D2 // B1 = C1.Parent | | +- D3 // C1 = C2.PrevSib | +- C2 // C2 = C1.NextSib | +- C3 // C1 = C1.FirstSib +- B2 // C3 = C1.LastSib | +- C4 // B1 = A1.FirstChild | +- C5 // B3 = A1.LastChild | +- C6 // B1 = A1.FirstDesc +- B3 // C7 = A1.LastDesc +- C7 DataStructures.GenericNode <string> A1 = new DataStructures.GenericNode <string>("A1", "A1", null); DataStructures.GenericNode <string> B1 = new DataStructures.GenericNode <string>("B1", "B1", null); DataStructures.GenericNode <string> B2 = new DataStructures.GenericNode <string>("B2", "B2", null); DataStructures.GenericNode <string> B3 = new DataStructures.GenericNode <string>("B3", "B3", null); DataStructures.GenericNode <string> C1 = new DataStructures.GenericNode <string>("C1", "C1", null); DataStructures.GenericNode <string> C2 = new DataStructures.GenericNode <string>("C2", "C2", null); DataStructures.GenericNode <string> C3 = new DataStructures.GenericNode <string>("C3", "C3", null); DataStructures.GenericNode <string> C4 = new DataStructures.GenericNode <string>("C4", "C4", null); DataStructures.GenericNode <string> C5 = new DataStructures.GenericNode <string>("C5", "C5", null); DataStructures.GenericNode <string> C6 = new DataStructures.GenericNode <string>("C6", "C6", null); DataStructures.GenericNode <string> C7 = new DataStructures.GenericNode <string>("C7", "C7", null); DataStructures.GenericNode <string> D1 = new DataStructures.GenericNode <string>("D1", "D1", null); DataStructures.GenericNode <string> D2 = new DataStructures.GenericNode <string>("D2", "D2", null); DataStructures.GenericNode <string> D3 = new DataStructures.GenericNode <string>("D3", "D3", null); root.AddChild(A1, -1, false); { A1.AddChild(B1, -1, false); { B1.AddChild(C1, -1, false); { C1.AddChild(D1, -1, false); C1.AddChild(D2, -1, false); C1.AddChild(D3, -1, false); } B1.AddChild(C2, -1, false); B1.AddChild(C3, -1, false); } A1.AddChild(B2, -1, false); { B2.AddChild(C4, -1, false); B2.AddChild(C5, -1, false); B2.AddChild(C6, -1, false); } A1.AddChild(B3, -1, false); { B3.AddChild(C7, -1, false); } } return; }
public void Test_20_Clone() { DataStructures.GenericNode <string> root = new DataStructures.GenericNode <string>(); GenericNodeTestData.AddTestChildren(root); DataStructures.GenericCloningVisitor <string> visitor = new DataStructures.GenericCloningVisitor <string>(root, new DataStructures.GenericNodeCloner <string>()); root.VisitNodes(visitor, DataStructures.VisitationType.DecendentsDepthFirst); GenericNodeTestData.AssertTestChildren(visitor.TargetRoot); return; }
public void Test_00_DebugOutput() { DataStructures.GenericNode <string> root = new DataStructures.GenericNode <string>("", "", new DebugOutputNodeListener()); root.Value = "root"; root.Notify( new DataStructures.GenericNode <string> .NodeUpdateNotification( DataStructures.GenericNode <string> .NodeNotification.NotificationStatus.Completed , root)); GenericNodeTestData.AddTestChildren(root); return; }
//-------------------------------------------------------------------- public static void JumbleTestChildren(DataStructures.GenericNode <string> root) { DataStructures.GenericNode <string> child = null; child = root.FindDescNode("C1"); child.ClearChildren(false); child.AddChild(new DataStructures.GenericNode <string>("D1", "D1", null), -1, false); child.AddChild(new DataStructures.GenericNode <string>("D2", "D2", null), -1, false); child.AddChild(new DataStructures.GenericNode <string>("D3", "D3", null), -1, false); child = root.FindDescNode("C5"); child.ClearChildren(false); return; }
public void Test_10_CountingVisitorOnRoot() { DataStructures.GenericNode <string> root = new DataStructures.GenericNode <string>(); GenericNodeTestData.AddTestChildren(root); this._AssertCountingVisitor(root, DataStructures.VisitationType.None, 0); this._AssertCountingVisitor(root, DataStructures.VisitationType.Parents, 0); this._AssertCountingVisitor(root, DataStructures.VisitationType.PreviousSiblings, 0); this._AssertCountingVisitor(root, DataStructures.VisitationType.NextSiblings, 0); this._AssertCountingVisitor(root, DataStructures.VisitationType.PreviousNodes, 0); this._AssertCountingVisitor(root, DataStructures.VisitationType.NextNodes, 14); this._AssertCountingVisitor(root, DataStructures.VisitationType.Children, 1); // Not Implemented: this._AssertCountingVisitor( root, DataStructures.VisitationType.DecendentsBreadthFirst, 0 ); this._AssertCountingVisitor(root, DataStructures.VisitationType.DecendentsDepthFirst, 14); return; }
//-------------------------------------------------------------------- public static void AssertTestChildren(DataStructures.GenericNode <string> root) { Assert.AreEqual("D3", root.FindDescNode("C2").PrevNode.Value.ToString(), "D3 = C2.Prev"); Assert.AreEqual("C3", root.FindDescNode("C2").NextNode.Value.ToString(), "C3 = C2.Next"); Assert.AreEqual("A1", root.FindDescNode("C1").FirstNode.FirstChildNode.Value.ToString(), "A1 = C1.First.FirstChild"); // Special case. Assert.AreEqual("C7", root.FindDescNode("C1").LastNode.Value.ToString(), "C7 = C1.Last"); Assert.AreEqual("A1", root.FindDescNode("C1").RootNode.FirstChildNode.Value.ToString(), "A1 = C1.Root.FirstChild"); // Special case. Assert.AreEqual("B1", root.FindDescNode("C1").ParentNode.Value.ToString(), "B1 = C1.Parent"); Assert.AreEqual("C1", root.FindDescNode("C2").PrevSibNode.Value.ToString(), "C1 = C2.PrevSib"); Assert.AreEqual("C2", root.FindDescNode("C1").NextSibNode.Value.ToString(), "C2 = C1.NextSib"); Assert.AreEqual("C1", root.FindDescNode("C1").FirstSibNode.Value.ToString(), "C1 = C1.FirstSib"); Assert.AreEqual("C3", root.FindDescNode("C1").LastSibNode.Value.ToString(), "C3 = C1.LastSib"); Assert.AreEqual("B1", root.FindDescNode("A1").FirstChildNode.Value.ToString(), "B1 = A1.FirstChild"); Assert.AreEqual("B3", root.FindDescNode("A1").LastChildNode.Value.ToString(), "B3 = A1.LastChild"); Assert.AreEqual("B1", root.FindDescNode("A1").FirstDescNode.Value.ToString(), "B1 = A1.FirstDesc"); Assert.AreEqual("C7", root.FindDescNode("A1").LastDescNode.Value.ToString(), "C7 = A1.LastDesc"); return; }