Пример #1
0
Файл: Box.cs Проект: p0k0/t-tn
        public IEnumerable <string> Find(string searchPattern)
        {
            var factory = new ChainFactory();

            var targetNode = factory.Create(searchPattern);

            if (!_heads.Contains(targetNode))
            {
                return(Enumerable.Empty <string>());
            }

            var searchHead = _heads.SingleOrDefault(x => x.Data.Equals(searchPattern.First()));

            var accumulator = new PathAccumulator();
            var enumerator  = new EnumeratorAccumulatingBranches(searchHead, accumulator);

            while (enumerator.MoveNext())
            {
            }

            var pathEnumerator = new EnumeratorTraversingSpecifiedPath(searchHead, targetNode.SubNodes.LastOrDefault());

            while (pathEnumerator.MoveNext())
            {
            }

            IEnumerable <string> result = accumulator.Paths;

            if (pathEnumerator.IsDestinationReached)
            {
                result = result.Concat(new string[] { searchPattern });
            }

            return(result);
        }
Пример #2
0
        public void Able_accumulate_all_paths()
        {
            var factory = new ChainFactory();

            var treeHead = factory.Create("0");
            var subTreeA = factory.Create("123");
            var subTreeB = factory.Create("453");

            treeHead.AppendSub(subTreeA);
            treeHead.AppendSub(subTreeB);

            var accumulator = new PathAccumulator();

            var enumerable = new EnumeratorAccumulatingBranches(treeHead, accumulator);

            while (enumerable.MoveNext())
            {
            }

            var expected = new List <string> {
                "0123", "0453"
            };

            Assert.Equal(2, accumulator.Paths.Count);
            Assert.Contains(expected[0], accumulator.Paths);
            Assert.Contains(expected[1], accumulator.Paths);
        }