Inheritance: INode, INamedObject
コード例 #1
0
ファイル: GraphTests.cs プロジェクト: sq/Fracture
        public void BasicTraversal()
        {
            var root = new Node { Name = "root" };
            var childA = new Node { Name = "a" };
            var childB = new Node { Name = "b" };
            var subchildAA = new Node { Name = "a.a" };
            var subchildAB = new Node { Name = "a.b" };
            var subchildAAA = new Node { Name = "a.a.a" };

            root.Children.AddLast(childA);
            root.Children.AddLast(childB);
            childA.Children.AddLast(subchildAA);
            childA.Children.AddLast(subchildAB);
            subchildAA.Children.AddLast(subchildAAA);

            var nodes = root.TraverseDepthFirst().ToArray();
            Assert.AreEqual(new NodeInfo[] {
                new NodeInfo(root, null),
                new NodeInfo(childA, root),
                new NodeInfo(subchildAA, childA),
                new NodeInfo(subchildAAA, subchildAA),
                new NodeInfo(subchildAB, childA),
                new NodeInfo(childB, root)
            }, nodes);

            nodes = root.TraverseBreadthFirst().ToArray();
            Assert.AreEqual(new NodeInfo[] {
                new NodeInfo(root, null),
                new NodeInfo(childA, root),
                new NodeInfo(childB, root),
                new NodeInfo(subchildAA, childA),
                new NodeInfo(subchildAB, childA),
                new NodeInfo(subchildAAA, subchildAA)
            }, nodes);
        }
コード例 #2
0
ファイル: GraphTests.cs プロジェクト: sq/Fracture
        public void CycleTests()
        {
            var root = new Node { Name = "root" };
            var childA = new Node { Name = "a" };
            var childB = new Node { Name = "b" };
            var childC = new Node { Name = "c" };
            var childD = new Node { Name = "d" };

            root.Children.AddLast(childA);
            root.Children.AddLast(childB);
            root.Children.AddLast(childC);
            root.Children.AddLast(childD);

            foreach (var i in root.Children)
                foreach (var j in root.Children)
                    if (j != i)
                        i.AddChild(j);

            var depth = root.TraverseDepthFirst().ToArray();
            var breadth = root.TraverseBreadthFirst().ToArray();
            Assert.AreEqual(depth.Length, breadth.Length);
            var depthHash = new HashSet<NodeInfo>(depth);
            var breadthHash = new HashSet<NodeInfo>(breadth);
            depthHash.UnionWith(breadthHash);
            Assert.AreEqual(depthHash.Count, depth.Length);

            var writer = new GraphWriter();
            root.Serialize(writer);

            Assert.AreEqual(
                new string[] {
                    "begin(root)", "+root",
                    "+a", "+b", "+a", "-a",
                    "+c", "+a", "-a", "+b",
                    "-b", "+d", "+a", "-a",
                    "+b", "-b", "+c", "-c",
                    "-d", "-c", "+d", "-d",
                    "-b", "+c", "-c", "+d",
                    "-d", "-a", "+b", "-b",
                    "+c", "-c", "+d", "-d",
                    "-root", "end"
                },
                writer.Trace.ToArray()
            );
        }
コード例 #3
0
ファイル: GraphTests.cs プロジェクト: sq/Fracture
        public void GraphXmlSerialization()
        {
            var root = new Node { Name = "root" };
            var childA = new Node { Name = "a" };
            var childB = new Node { Name = "b" };
            var subchildAA = new Node { Name = "a.a" };

            root.Children.AddLast(childA);
            root.Children.AddLast(childB);
            childA.Children.AddLast(subchildAA);

            var sb = new StringBuilder();
            using (var xwriter = XmlWriter.Create(sb, null)) {
                xwriter.WriteStartElement("test");
                var writer = new XmlGraphWriter(xwriter, new AssemblyTypeResolver(Assembly.GetExecutingAssembly()));
                root.Serialize(writer);
                xwriter.WriteEndElement();
            }

            Assert.AreEqual(
                GraphXML,
                sb.ToString()
            );
        }
コード例 #4
0
ファイル: GraphTests.cs プロジェクト: sq/Fracture
        public void GraphSerialization()
        {
            var root = new Node { Name = "root" };
            var childA = new Node { Name = "a" };
            var childB = new Node { Name = "b" };
            var subchildAA = new Node { Name = "a.a" };
            var subchildAB = new Node { Name = "a.b" };
            var subchildAAA = new Node { Name = "a.a.a" };

            root.Children.AddLast(childA);
            root.Children.AddLast(childB);
            childA.Children.AddLast(subchildAA);
            childA.Children.AddLast(subchildAB);
            subchildAA.Children.AddLast(subchildAAA);

            var writer = new GraphWriter();
            root.Serialize(writer);

            Assert.AreEqual(
                new string[] { "begin(root)", "+root", "+a", "+a.a", "+a.a.a", "-a.a.a", "-a.a", "+a.b", "-a.b", "-a", "+b", "-b", "-root", "end" },
                writer.Trace.ToArray()
            );
        }