Пример #1
0
        public void SourceWithSingleValue_ReturnsJustCurrent()
        {
            var iterator = EnumerableEx.Return(0).ToPrevNextIterator();
            var standard = new[] { new PrevNextValue <int>(Optional <int> .None, 0, Optional <int> .None) };

            CollectionAssert.AreEqual(iterator, standard);
        }
Пример #2
0
        static IEnumerable <IEnumerable <T> > SplitWithBordersIterator <T>(IEnumerable <T> source,
                                                                           Relation <T, T, T> relation)
        {
            List <T> acc;

            using (var enumerator = source.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    yield break;
                }

                T first = enumerator.Current;

                if (!enumerator.MoveNext())
                {
                    yield return(EnumerableEx.Return(first));

                    yield break;
                }

                T second = enumerator.Current;
                acc = new List <T> {
                    first, second
                };

                while (enumerator.MoveNext())
                {
                    T item = enumerator.Current;
                    if (relation(first, second, item))
                    {
                        acc.Add(item);
                    }
                    else
                    {
                        yield return(acc);

                        acc = new List <T> {
                            second, item
                        };
                    }

                    first  = second;
                    second = item;
                }
            }

            if (acc.Count > 0)
            {
                yield return(acc);
            }
        }
Пример #3
0
        public void Except_OnlyTargetItem_ReturnsEmpty()
        {
            var items = EnumerableEx.Return(0);

            CollectionAssert.IsEmpty(items.Except(0));
        }
Пример #4
0
 public static IEnumerable <T> Generate <T>(T state, Predicate <T> condition, Func <T, T> iterate)
 {
     return(EnumerableEx.Generate(state, x => condition(x), iterate, Functions.Identity <T>()));
 }