Exemple #1
0
        public void IterationThroughCollection_SeveralIterators_IteratesEndlessly()
        {
            int iteratorsAmount = 3;

            var source     = Enumerable.Range(0, sourceLength).ToList();
            var enumerable = new RoundRobinCollectionEnumerable <int>(source);

            IList <IEnumerator <int> > iterators = Enumerable.Range(0, iteratorsAmount)
                                                   .Select(i => enumerable.GetEnumerator()).ToList();

            List <int> expected = new List <int>();

            for (int i = 0; i < iteratorsAmount; i++)
            {
                expected.AddRange(source);
            }

            var actual = new List <int>();

            for (int i = 0; i < sourceLength; i++)
            {
                foreach (var iter in iterators)
                {
                    iter.MoveNext();
                    actual.Add(iter.Current);
                }
            }

            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        public void IterationThroughCollection_SingleIteratorAndSeveralIterations_IteratesEndlessly()
        {
            int iterationAmount = 3;

            var source     = Enumerable.Range(0, sourceLength).ToList();
            var enumerable = new RoundRobinCollectionEnumerable <int>(source);

            List <int> expected = new List <int>();

            for (int i = 0; i < iterationAmount; i++)
            {
                expected.AddRange(source);
            }
            ;
            var iter = enumerable.GetEnumerator();

            var actual = Enumerable.Range(0, sourceLength * iterationAmount)
                         .Select(i =>
            {
                iter.MoveNext();
                return(iter.Current);
            }).ToList();

            Assert.AreEqual(expected, actual);
        }