public void TestInsertNode() { MacroscopeBinaryTreeGeneric <int> Tree = new MacroscopeBinaryTreeGeneric <int> (); const string Name = "root"; int Value = new Random().Next(1, 666); Assert.IsNotNull(Tree, "Tree is null"); MacroscopeBinaryTreeGenericNode <int> Node = Tree.SetRootNode(Name, Value); Assert.IsNotNull(Node, "Root node is null"); Assert.AreEqual(Name, Node.GetNodeName(), "Node name does not match"); Assert.AreEqual(Value, Node.GetNodeValue(), "Node value does not match"); }
/**************************************************************************/ private MacroscopeBinaryTreeGenericNode <T> InsertNode( MacroscopeBinaryTreeGenericNode <T> Node, MacroscopeBinaryTreeGenericNode <T> NewNode ) { // TODO: This is broken this.DebugMsg("InsertNode"); this.DebugMsg(string.Format("NewNode: {0}", NewNode.GetNodeName())); MacroscopeBinaryTreeGenericNode <T> ChildNode; T NodeValue = Node.GetNodeValue(); T NewNodeValue = NewNode.GetNodeValue(); this.DebugMsg(string.Format("NodeValue/NodeValue: {0} / {1}", NodeValue, NewNodeValue)); MacroscopeBinaryTreeGenericNode <T> .NodeOrientation Orientation; if (NewNodeValue.CompareTo(NodeValue) <= 0) { Orientation = MacroscopeBinaryTreeGenericNode <T> .NodeOrientation.LEFT; } else { Orientation = MacroscopeBinaryTreeGenericNode <T> .NodeOrientation.RIGHT; } ChildNode = Node.GetChildNode(Orientation: Orientation); this.DebugMsg(string.Format("Orientation: {0}", Orientation)); if (ChildNode == null) { Node.AddChildNode(Orientation: Orientation, ChildNode: NewNode); } else { this.InsertNode(Node: ChildNode, NewNode: NewNode); } return(NewNode); }