Exemple #1
0
        public void DepthFirstEnumeratorsAreLazyAndDisposeProperly()
        {
            var helper = new EnumeratorHelper();

            var sequence = Traverse.DepthFirst(10, i => helper.MakeEnumerator(i - 1));

            helper.IterateCount.ShouldEqual(0);
            helper.StartCount.ShouldEqual(0);
            helper.EndCount.ShouldEqual(0);

            using (var enumerator = sequence.GetEnumerator())
            {
                for (var i = 0; i < 10; ++i)
                {
                    enumerator.MoveNext().ShouldEqual(true);
                }
                helper.IterateCount.ShouldEqual(9); // -1 for root
            }

            helper.StartCount.ShouldEqual(helper.EndCount);
        }
Exemple #2
0
        public void BreadthFirstEnumeratorsAreLazyAndDisposeProperly()
        {
            var helper = new EnumeratorHelper();

            var sequence = Traverse.BreadthFirst(10, i => helper.MakeEnumerator(i - 1));

            Assert.AreEqual(0, helper.IterateCount);
            Assert.AreEqual(0, helper.StartCount);
            Assert.AreEqual(0, helper.EndCount);

            using (var enumerator = sequence.GetEnumerator())
            {
                for (var i = 0; i < 10; ++i)
                {
                    Assert.IsTrue(enumerator.MoveNext());
                }
                Assert.AreEqual(9, helper.IterateCount); // -1 for root
            }

            Assert.AreEqual(helper.EndCount, helper.StartCount);
        }