Exemple #1
0
        public void TraverseSingles()
        {
            var a = new StringNode("a");
            var b = new StringNode("b");
            var c = new StringNode("c");
            var d = new StringNode("d");
            var e = new StringNode("e");
            var f = new StringNode("f");
            var g = new StringNode("g");
            // a - b - c - d - e
            //   - g         - f
            a.AddFirst(b);
            a.AddLast(g);
            b.AddFirst(c);
            c.AddFirst(d);
            d.AddFirst(e);
            d.AddLast(f);

            string.Join("", b.DescendantsOfSingle().Select(n => n.Value)).Should()
                    .Be("cd");
            string.Join("", b.DescendantsOfSingleAndSelf().Select(n => n.Value)).Should()
                    .Be("bcd");
            string.Join("", c.DescendantsOfSingle().Select(n => n.Value)).Should()
                    .Be("d");
            string.Join("", c.DescendantsOfSingleAndSelf().Select(n => n.Value)).Should()
                    .Be("cd");

            string.Join("", b.AncestorsWithSingleChild().Select(n => n.Value)).Should()
                    .Be("");
            string.Join("", b.AncestorsWithSingleChildAndSelf().Select(n => n.Value)).Should()
                    .Be("b");
            string.Join("", c.AncestorsWithSingleChild().Select(n => n.Value)).Should()
                    .Be("b");
            string.Join("", c.AncestorsWithSingleChildAndSelf().Select(n => n.Value)).Should()
                    .Be("cb");
            string.Join("", d.AncestorsWithSingleChild().Select(n => n.Value)).Should()
                    .Be("cb");
            string.Join("", d.AncestorsWithSingleChildAndSelf().Select(n => n.Value)).Should()
                    .Be("dcb");
            string.Join("", e.AncestorsWithSingleChild().Select(n => n.Value)).Should()
                    .Be("");
            string.Join("", e.AncestorsWithSingleChildAndSelf().Select(n => n.Value)).Should()
                    .Be("e");
        }