Пример #1
0
        public void AncestorsTest()
        {
            var root = TreeNodeTest.GetTestedTree();

            TreeNodeTest.Ancestors.NodeA(root);
            TreeNodeTest.Ancestors.NodeC(root);
            TreeNodeTest.Ancestors.NodeD(root);
            TreeNodeTest.Ancestors.NodeG(root);
        }
Пример #2
0
        public void DescendantsTest()
        {
            var root = TreeNodeTest.GetTestedTree();

            var descendants = root.Descendants.ToArray();

            Assert.AreEqual(descendants.Length, 6);

            // A

            var a = (
                from node in descendants
                where node.Data == "A" select node).FirstOrDefault();

            Assert.IsNull(a);

            // B

            var b = (
                from node in descendants
                where node.Data == "B" select node).FirstOrDefault();

            Assert.IsNotNull(b);

            var actual = b;

            Assert.IsTrue(actual.Children.Count == 0);
            Assert.AreEqual(actual.Data, "B");
            Assert.IsTrue(actual.IsTerminal == true);
            Assert.IsTrue(actual.IsBranch == false);
            Assert.IsTrue(actual.Level == 1);
            Assert.IsTrue(actual.Degree == 0);
            Assert.IsTrue(actual.IsRoot == false);

            // C

            var c = (
                from node in descendants
                where node.Data == "C" select node).FirstOrDefault();

            Assert.IsNotNull(c);

            actual = c;

            Assert.IsTrue(actual.Children.Count == 3);
            Assert.AreEqual(actual.Data, "C");
            Assert.IsTrue(actual.IsTerminal == false);
            Assert.IsTrue(actual.IsBranch == true);
            Assert.IsTrue(actual.Level == 1);
            Assert.IsTrue(actual.Degree == 3);
            Assert.IsTrue(actual.IsRoot == false);

            // D

            var d = (
                from node in descendants
                where node.Data == "D" select node).FirstOrDefault();

            Assert.IsNotNull(d);

            actual = d;

            Assert.IsTrue(actual.Children.Count == 0);
            Assert.AreEqual(actual.Data, "D");
            Assert.IsTrue(actual.IsTerminal == true);
            Assert.IsTrue(actual.IsBranch == false);
            Assert.IsTrue(actual.Level == 2);
            Assert.IsTrue(actual.Degree == 0);
            Assert.IsTrue(actual.IsRoot == false);

            // E

            var e = (
                from node in descendants
                where node.Data == "E" select node).FirstOrDefault();

            Assert.IsNotNull(e);

            actual = e;

            Assert.IsTrue(actual.Children.Count == 0);
            Assert.AreEqual(actual.Data, "E");
            Assert.IsTrue(actual.IsTerminal == true);
            Assert.IsTrue(actual.IsBranch == false);
            Assert.IsTrue(actual.Level == 2);
            Assert.IsTrue(actual.Degree == 0);
            Assert.IsTrue(actual.IsRoot == false);

            // F

            var f = (
                from node in descendants
                where node.Data == "F" select node).FirstOrDefault();

            Assert.IsNotNull(f);

            actual = f;

            Assert.IsTrue(actual.Children.Count == 1);
            Assert.AreEqual(actual.Data, "F");
            Assert.IsTrue(actual.IsTerminal == false);
            Assert.IsTrue(actual.IsBranch == true);
            Assert.IsTrue(actual.Level == 2);
            Assert.IsTrue(actual.Degree == 1);
            Assert.IsTrue(actual.IsRoot == false);

            // G

            var g = (
                from node in descendants
                where node.Data == "G" select node).FirstOrDefault();

            Assert.IsNotNull(g);

            actual = g;

            Assert.IsTrue(actual.Children.Count == 0);
            Assert.AreEqual(actual.Data, "G");
            Assert.IsTrue(actual.IsTerminal == true);
            Assert.IsTrue(actual.IsBranch == false);
            Assert.IsTrue(actual.Level == 3);
            Assert.IsTrue(actual.Degree == 0);
            Assert.IsTrue(actual.IsRoot == false);
        }