Commits

Mark Heath  committed 778a945

renaming NodeInfo to Node

  • Participants
  • Parent commits 18f1a26

Comments (0)

Files changed (8)

File GraphPad.Tests/NodeInfoTests.cs

         [Test]
         public void CanAddAParentRelationship()
         {
-            var parent = new NodeInfo() { Name = "parent" };
-            var child = new NodeInfo() { Name = "child" };
+            var parent = new Node() { Name = "parent" };
+            var child = new Node() { Name = "child" };
             parent.AddChild(child);
             Assert.AreEqual(1, parent.Children.Count());
             Assert.AreEqual(0, parent.Parents.Count());

File GraphPad/GraphPad.csproj

     <Compile Include="Logic\Graph.cs" />
     <Compile Include="Logic\GraphBuilder.cs" />
     <Compile Include="Logic\GraphRenderer.cs" />
-    <Compile Include="Logic\NodeInfo.cs" />
+    <Compile Include="Logic\Node.cs" />
     <Compile Include="Logic\RelationshipType.cs" />
     <Compile Include="NodeControl.xaml.cs">
       <DependentUpon>NodeControl.xaml</DependentUpon>

File GraphPad/Logic/Connection.cs

 {
     class Connection
     {
-        public NodeInfo TargetNode { get; set; }
+        public Node TargetNode { get; set; }
         public RelationshipType Relationship { get; set; }
     }
 }

File GraphPad/Logic/Graph.cs

 {
     class Graph
     {
-        private readonly List<NodeInfo> nodes;
+        private readonly List<Node> nodes;
 
         public Graph()
         {
-            this.nodes = new List<NodeInfo>();
+            this.nodes = new List<Node>();
         }
 
-        public IEnumerable<NodeInfo> RootNodes { get { return nodes.Where(n => n.IsRootNode()); } }
-        public IEnumerable<NodeInfo> LeafNodes { get { return nodes.Where(n => n.IsLeafNode()); } }
+        public IEnumerable<Node> RootNodes { get { return nodes.Where(n => n.IsRootNode()); } }
+        public IEnumerable<Node> LeafNodes { get { return nodes.Where(n => n.IsLeafNode()); } }
 
-        public IList<NodeInfo> Nodes { get { return nodes; } }
+        public IList<Node> Nodes { get { return nodes; } }
         
-        public IEnumerable<NodeInfo> FindLongestPath()
+        public IEnumerable<Node> FindLongestPath()
         {
-            return FindLongest(new List<NodeInfo>(), RootNodes);
+            return FindLongest(new List<Node>(), RootNodes);
         }
 
-        private List<NodeInfo> FindLongest(List<NodeInfo> pathSoFar, IEnumerable<NodeInfo> nodesToTest)
+        private List<Node> FindLongest(List<Node> pathSoFar, IEnumerable<Node> nodesToTest)
         {
             var longest = pathSoFar;
             foreach (var node in nodesToTest)
             {
-                var newPath = new List<NodeInfo>();
+                var newPath = new List<Node>();
                 newPath.AddRange(pathSoFar);
                 newPath.Add(node);
                 var testPath = FindLongest(newPath, node.Children);

File GraphPad/Logic/GraphBuilder.cs

         public Graph GenerateGraph(string text)
         {
             var tokens = Tokenizer.Tokenize(text);
-            var nodes = new Dictionary<string, NodeInfo>();
-            NodeInfo lastNode = null;
+            var nodes = new Dictionary<string, Node>();
+            Node lastNode = null;
             foreach (var token in tokens)
             {
                 switch (token)
                         lastNode = null;
                         break;
                     default:
-                        NodeInfo node;
+                        Node node;
                         if (nodes.ContainsKey(token))
                         {
                             node = nodes[token];
                         }
                         else
                         {
-                            node = new NodeInfo() { Name = token };
+                            node = new Node() { Name = token };
                             nodes[token] = node;
                         }
                         if (lastNode != null)

File GraphPad/Logic/GraphRenderer.cs

             canvas.Height = nodes.Values.Max(x => (double)x.GetValue(Canvas.TopProperty) + x.Height + nodePadding);
         }
 
-        private void MoveDown(NodeInfo nodeInfo)
+        private void MoveDown(Node nodeInfo)
         {
             var node = nodes[nodeInfo.Name];
             double yPosition = (double)node.GetValue(Canvas.TopProperty);

File GraphPad/Logic/Node.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace GraphPad.Logic
+{
+    class Node
+    {
+        public Node()
+        {
+            this.Connections = new List<Connection>();
+        }
+
+        public void AddChild(Node child)
+        {
+            AddConnection(child, RelationshipType.Child);
+        }
+
+        private void AddConnection(Node connectTo, RelationshipType relationshipType)
+        {
+            if (connectTo == null)
+                throw new ArgumentNullException();
+            if (connectTo == this)
+                throw new ArgumentException("Don't support connection to self");
+
+            var existingConnection = Connections.Where(c => c.TargetNode == connectTo).FirstOrDefault();
+            if (existingConnection != null && existingConnection.Relationship == relationshipType)
+            {
+                // avoid infinite loop
+                return;
+            }
+            else if (existingConnection != null)
+            {
+                throw new ArgumentException("Already connected to this node");
+            }
+
+            this.Connections.Add(new Connection() { TargetNode = connectTo, Relationship = relationshipType });
+            connectTo.AddConnection(this, GetReciprocalRelationship(relationshipType));
+        }
+
+        private RelationshipType GetReciprocalRelationship(RelationshipType relationshipType)
+        {
+            if (relationshipType == RelationshipType.Child)
+                return RelationshipType.Parent;
+            else if (relationshipType == RelationshipType.Parent)
+                return RelationshipType.Child;
+            else
+                return RelationshipType.Peer;
+        }   
+
+        public string Name { get; set; }
+        public IEnumerable<Node> Parents { get { return Connections.Where(x => x.Relationship == RelationshipType.Parent).Select(x => x.TargetNode); } }
+        public IEnumerable<Node> Children { get { return Connections.Where(x => x.Relationship == RelationshipType.Child).Select(x => x.TargetNode); } }
+        private IList<Connection> Connections { get; set; }
+        public override string ToString()
+        {
+            return String.Format("Node {0}", Name);
+        }
+
+        public bool IsRootNode()
+        {
+            return !Parents.Any();
+        }
+
+        public bool IsLeafNode()
+        {
+            return !Children.Any();
+        }
+    }
+}

File GraphPad/Logic/NodeInfo.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace GraphPad.Logic
-{
-    class NodeInfo
-    {
-        public NodeInfo()
-        {
-            this.Connections = new List<Connection>();
-        }
-
-        public void AddChild(NodeInfo child)
-        {
-            AddConnection(child, RelationshipType.Child);
-        }
-
-        private void AddConnection(NodeInfo connectTo, RelationshipType relationshipType)
-        {
-            if (connectTo == null)
-                throw new ArgumentNullException();
-            if (connectTo == this)
-                throw new ArgumentException("Don't support connection to self");
-
-            var existingConnection = Connections.Where(c => c.TargetNode == connectTo).FirstOrDefault();
-            if (existingConnection != null && existingConnection.Relationship == relationshipType)
-            {
-                // avoid infinite loop
-                return;
-            }
-            else if (existingConnection != null)
-            {
-                throw new ArgumentException("Already connected to this node");
-            }
-
-            this.Connections.Add(new Connection() { TargetNode = connectTo, Relationship = relationshipType });
-            connectTo.AddConnection(this, GetReciprocalRelationship(relationshipType));
-        }
-
-        private RelationshipType GetReciprocalRelationship(RelationshipType relationshipType)
-        {
-            if (relationshipType == RelationshipType.Child)
-                return RelationshipType.Parent;
-            else if (relationshipType == RelationshipType.Parent)
-                return RelationshipType.Child;
-            else
-                return RelationshipType.Peer;
-        }   
-
-        public string Name { get; set; }
-        public IEnumerable<NodeInfo> Parents { get { return Connections.Where(x => x.Relationship == RelationshipType.Parent).Select(x => x.TargetNode); } }
-        public IEnumerable<NodeInfo> Children { get { return Connections.Where(x => x.Relationship == RelationshipType.Child).Select(x => x.TargetNode); } }
-        private IList<Connection> Connections { get; set; }
-        public override string ToString()
-        {
-            return String.Format("Node {0}", Name);
-        }
-
-        public bool IsRootNode()
-        {
-            return !Parents.Any();
-        }
-
-        public bool IsLeafNode()
-        {
-            return !Children.Any();
-        }
-    }
-}