예제 #1
0
        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()
                );
        }
예제 #2
0
        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()
                );
        }
예제 #3
0
        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()
                );
        }
예제 #4
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()
            );
        }
예제 #5
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()
            );
        }
예제 #6
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()
            );
        }