Esempio n. 1
0
        public void TreeTraversal_ArbitraryStartPoint_IncludeSelfOffWorks()
        {
            /*
             *
             *      root
             *       /|\
             *      / | \
             *     a  b  c
             *    /|\     \
             *   / | \     \
             * aa  ab  ac    ca
             *    /|\       | \
             *   / | \      |  \
             * aba abb abc  caa cab
             *
             * */

            var arbitraryStartPointIter = TreeTraversal <TestTreePart> .IteratorAt(root, new TreeNodePath(0, 1));

            Assert.AreEqual("a.b", arbitraryStartPointIter.Node.Value);
            var found = TreeTraversal <TestTreePart> .All(arbitraryStartPointIter.Node, arbitraryStartPointIter.Node, includeSelf : false).FirstOrDefault();

            Assert.AreEqual("a.b.a", found.Value);

            var iterEnd = TreeTraversal <TestTreePart> .IteratorAt(root, new TreeNodePath(0, 1, 0));

            Assert.AreEqual("a.b.a", iterEnd.Node.Value);

            Assert.AreEqual(found, iterEnd.Node);
        }
Esempio n. 2
0
        public void TreeTraversal_DepthFirstWorks()
        {
            int expectationIndex = 0;

            foreach (TestTreePart node in TreeTraversal <TestTreePart> .All(root, eTraversalFlowDirection.ThroughChildren, eTraversalStrategy.DepthFirst))
            {
                Assert.AreEqual(kDFS_Order[expectationIndex++], node.Value);
            }
        }
Esempio n. 3
0
        public void TreeTraversal_ReverseIteration_DFS_Works()
        {
            var forwards = TreeTraversal <TestTreePart> .All(root, eTraversalFlowDirection.ThroughChildren, eTraversalStrategy.DepthFirst).Select(_ => _.Value).ToList();

            var backwards = TreeTraversal <TestTreePart> .All(end, eTraversalFlowDirection.ReversedThroughChildren, eTraversalStrategy.DepthFirst).Select(_ => _.Value).ToList();


            backwards.Reverse();

            Assert.AreEqual(forwards.Count, backwards.Count);
            for (int index = 0; index < forwards.Count; ++index)
            {
                Assert.AreEqual(forwards[index], backwards[index]);
            }
        }
Esempio n. 4
0
 public void TreeTraversal_CanIterateOverSeveral()
 {
     Assert.AreEqual(13, TreeTraversal <TestTreePart> .All(root).Count());
 }