Inheritance: IGraphWriter
コード例 #1
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()
                );
        }
コード例 #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
        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 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()
            );
        }