Пример #1
0
        public void ElementAt_Skip_Take_Predicate_Selector_With_OutOfRange_Must_Return_None(int[] source, int skipCount, int takeCount, Func <int, bool> predicate, Func <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap.AsReadOnlyList(source);

            // Act
            var optionTooSmall = ReadOnlyListExtensions
                                 .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skipCount)
                                 .Take(takeCount)
                                 .Where(predicate)
                                 .Select(selector)
                                 .ElementAt(-1);
            var optionTooLarge = ReadOnlyListExtensions
                                 .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skipCount)
                                 .Take(takeCount)
                                 .Where(predicate)
                                 .Select(selector)
                                 .ElementAt(takeCount);

            // Assert
            _ = optionTooSmall.Must()
                .BeOfType <Option <string> >()
                .EvaluateTrue(option => option.IsNone);
            _ = optionTooLarge.Must()
                .BeOfType <Option <string> >()
                .EvaluateTrue(option => option.IsNone);
        }
Пример #2
0
        public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, int skipCount, int takeCount, Predicate <int> predicate, NullableSelector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Where(predicate.AsFunc())
                           .Select(selector.AsFunc())
                           .Single();

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skipCount)
                         .Take(takeCount)
                         .Where(predicate)
                         .Select(selector)
                         .Single();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Пример #3
0
        public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func <int, bool> predicate, Func <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList <int>(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .Where(predicate)
                           .Select(selector)
                           .First();

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skip)
                         .Take(take)
                         .Where(predicate)
                         .Select(selector)
                         .First();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Пример #4
0
        public void ToList_Skip_Take_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount, Predicate <int> predicate, NullableSelector <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Where(predicate.AsFunc())
                           .Select(selector.AsFunc())
                           .ToArray();

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skipCount)
                         .Take(takeCount)
                         .Where(predicate)
                         .Select(selector)
                         .ToList();

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
        public void ToArray_Predicate_Selector_Must_Succeed(int[] source, int skip, int take, Func <int, bool> predicate, Func <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .Where(predicate)
                           .Select(selector)
                           .ToArray();

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skip)
                         .Take(take)
                         .Where(predicate)
                         .Select(selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeNotSameAs(source)
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
Пример #6
0
        public void ElementAt_Skip_Take_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, int skipCount, int takeCount, Func <int, bool> predicate, Func <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Where(predicate)
                           .Select(selector)
                           .ToList();

            for (var index = 0; index < expected.Count; index++)
            {
                // Act
                var result = ReadOnlyListExtensions
                             .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skipCount)
                             .Take(takeCount)
                             .Where(predicate)
                             .Select(selector)
                             .ElementAt(index);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected[index]),
                    () => throw new Exception());
            }
        }
Пример #7
0
        public int WhereHyper()
        {
            var sum = 0;

            foreach (var item in ReadOnlyListExtensions.Where <ImmutableArray <int>, int>(array, item => (item & 0x01) == 0))
            {
                sum += item;
            }
            return(sum);
        }
        public void ReadOnlyListExtensions_Basics()
        {
            Assert.True(ReadOnlyListExtensions.AreEqual <int>(null, null));
            Assert.False(ReadOnlyListExtensions.AreEqual <int>(new int[] { 1 }, null));

            int[] array = Enumerable.Range(0, 100).ToArray();
            int   last  = -1;

            ReadOnlyListExtensions.ForEachReverse(array, (value) => last = value);
            Assert.Equal(0, last);
        }
Пример #9
0
        public int SelectHyper()
        {
            var source = ReadOnlyListExtensions.Select <ImmutableArray <int>, int, int>(array, item => item);
            var sum    = 0;

            for (var index = 0; index < source.Count; index++)
            {
                sum += source[index];
            }
            return(sum);
        }
Пример #10
0
 public override bool Equals(object obj)
 {
     if (obj is ArraySlice <T> )
     {
         return(Equals((ArraySlice <T>)obj));
     }
     else
     {
         return(ReadOnlyListExtensions.AreEqual(this, obj as IReadOnlyList <T>));
     }
 }
        public int Hyperlinq_List_Reference()
        {
            var sum = 0;

            foreach (var item in ReadOnlyListExtensions.SelectMany <
                         ReadOnlyListExtensions.ValueEnumerableWrapper <int>, int,
                         ValueEnumerable.ReturnEnumerable <int>, ValueEnumerable.ReturnEnumerable <int> .DisposableEnumerator, int>(
                         ReadOnlyListExtensions.AsValueEnumerable <int>(listReference), item => ValueEnumerable.Return(item)))
            {
                sum += item;
            }
            return(sum);
        }
Пример #12
0
        public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source)
        {
            // Arrange
            var value   = System.Linq.Enumerable.Last(source).ToString();
            var wrapped = Wrap.AsValueReadOnlyList(source.AsValueEnumerable().Select(item => item.ToString()).ToArray());

            // Act
            var result = ReadOnlyListExtensions
                         .Contains <Wrap.ValueReadOnlyListWrapper <string>, string>(wrapped, value);

            // Assert
            _ = result.Must()
                .BeTrue();
        }
Пример #13
0
        public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source)
        {
            // Arrange
            var value   = System.Linq.Enumerable.Last(source);
            var wrapped = Wrap.AsValueReadOnlyList(source);

            // Act
            var result = ReadOnlyListExtensions
                         .Contains <Wrap.ValueReadOnlyListWrapper <int>, int>(wrapped, value);

            // Assert
            _ = result.Must()
                .BeTrue();
        }
        public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source)
        {
            // Arrange
            var value   = default(string);
            var wrapped = Wrap.AsValueReadOnlyList(source.Select(item => item.ToString()).ToArray());

            // Act
            var result = ReadOnlyListExtensions
                         .Contains <Wrap.ValueReadOnlyListWrapper <string>, string>(wrapped, value);

            // Assert
            _ = result.Must()
                .BeFalse();
        }
        public void Skip_With_ValidData_Must_Succeed(int[] source, int count)
        {
            // Arrange
            var wrapped  = Wrap.AsValueReadOnlyList(source);
            var expected = System.Linq.Enumerable.Skip(source, count);

            // Act
            var result = ReadOnlyListExtensions.Skip <Wrap.ValueReadOnlyListWrapper <int>, int>(wrapped, count);

            // Assert
            _ = result.Must()
                .BeEnumerableOf <int>()
                .BeEqualTo(expected);
        }
Пример #16
0
        public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source)
        {
            // Arrange
            var value   = int.MaxValue;
            var wrapped = Wrap.AsValueReadOnlyList(source);

            // Act
            var result = ReadOnlyListExtensions
                         .Contains <Wrap.ValueReadOnlyListWrapper <int>, int>(wrapped, value, EqualityComparer <int> .Default);

            // Assert
            _ = result.Must()
                .BeFalse();
        }
Пример #17
0
        public void Select_With_NullSelector_Must_Throw()
        {
            // Arrange
            var source   = Wrap.AsReadOnlyList(new int[0]);
            var selector = (NullableSelectorAt <int, string>)null;

            // Act
            Action action = () => _ = ReadOnlyListExtensions.Select <Wrap.ReadOnlyListWrapper <int>, int, string>(source, selector);

            // Assert
            _ = action.Must()
                .Throw <ArgumentNullException>()
                .EvaluateTrue(exception => exception.ParamName == "selector");
        }
        public void All_With_NullPredicate_Must_Throw()
        {
            // Arrange
            var wrapped   = Wrap.AsValueReadOnlyList(new int[0]);
            var predicate = (Predicate <int>)null;

            // Act
            Action action = () => _ = ReadOnlyListExtensions
                                      .All <Wrap.ValueReadOnlyListWrapper <int>, int>(wrapped, predicate);

            // Assert
            _ = action.Must()
                .Throw <ArgumentNullException>()
                .EvaluateTrue(exception => exception.ParamName == "predicate");
        }
Пример #19
0
        public void First_With_Empty_Must_Return_None(int[] source)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList <int>(source);

            // Act
            var result = ReadOnlyListExtensions
                         .First <Wrap.ReadOnlyListWrapper <int>, int>(wrapped);

            // Assert
            _ = result.Must()
                .BeOfType <Option <int> >()
                .EvaluateTrue(option => option.IsNone);
        }
Пример #20
0
        public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate)
        {
            // Arrange
            var wrapped  = Wrap.AsValueReadOnlyList(source);
            var expected =
                System.Linq.Enumerable.Any(wrapped, predicate.AsFunc());

            // Act
            var result = ReadOnlyListExtensions
                         .Any <Wrap.ValueReadOnlyListWrapper <int>, int>(wrapped, predicate);

            // Assert
            _ = result.Must()
                .BeEqualTo(expected);
        }
Пример #21
0
        public void Where_With_NullPredicate_Must_Throw()
        {
            // Arrange
            var list = Wrap
                       .AsReadOnlyList(new int[0]);
            var predicate = (PredicateAt <int>)null;

            // Act
            Action action = () => _ = ReadOnlyListExtensions.Where(list, predicate);

            // Assert
            _ = action.Must()
                .Throw <ArgumentNullException>()
                .EvaluateTrue(exception => exception.ParamName == "predicate");
        }
        public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate)
        {
            // Arrange
            var wrapped  = Wrap.AsValueReadOnlyList(source);
            var expected =
                System.Linq.Enumerable.Count(
                    System.Linq.Enumerable.Where(source, predicate.AsFunc())) == source.Length;

            // Act
            var result = ReadOnlyListExtensions
                         .All <Wrap.ValueReadOnlyListWrapper <int>, int>(wrapped, predicate);

            // Assert
            _ = result.Must()
                .BeEqualTo(expected);
        }
Пример #23
0
        public void WhereSelect_Predicate_With_Null_Must_Throw()
        {
            // Arrange
            var source    = Wrap.AsReadOnlyList(new int[0]);
            var predicate = (Predicate <int>)null;

            // Act
            Action action = () => _ = ReadOnlyListExtensions
                                      .Where <Wrap.ReadOnlyListWrapper <int>, int>(source, predicate)
                                      .Select(item => item.ToString());

            // Assert
            _ = action.Must()
                .Throw <ArgumentNullException>()
                .EvaluateTrue(exception => exception.ParamName == "predicate");
        }
        public void Count_With_ValidData_Must_Succeed(int[] source)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList(source);
            var expected = Enumerable
                           .Count(source);

            // Act
            var result = ReadOnlyListExtensions
                         .Count <Wrap.ReadOnlyListWrapper <int>, int>(wrapped);

            // Assert
            _ = result.Must()
                .BeEqualTo(expected);
        }
Пример #25
0
        public void Select_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected =
                System.Linq.Enumerable.Select(wrapped, selector.AsFunc());

            // Act
            var result = ReadOnlyListExtensions
                         .Select <Wrap.ReadOnlyListWrapper <int>, int, string>(wrapped, selector);

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
Пример #26
0
        public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList(source);

            // Act
            var result = ReadOnlyListExtensions
                         .AsValueEnumerable(wrapped);

            // Assert
            _ = result.Must()
                .BeOfType <ReadOnlyListExtensions.ValueEnumerableWrapper <int> >()
                .BeEnumerableOf <int>()
                .BeEqualTo(wrapped);
        }
Пример #27
0
        public void Contains_Skip_Take_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take)
        {
            // Arrange
            var value   = int.MaxValue;
            var wrapped = Wrap.AsValueReadOnlyList(source);

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ValueReadOnlyListWrapper <int>, int>(wrapped, skip)
                         .Take(take)
                         .Contains(value, TestComparer <int> .Instance);

            // Assert
            _ = result.Must()
                .BeFalse();
        }
Пример #28
0
        public void ToList_Predicate_With_Null_Must_Throw()
        {
            // Arrange
            var source    = new int[0];
            var wrapped   = Wrap.AsReadOnlyList(source);
            var predicate = (Predicate <int>)null;

            // Act
            Action action = () => _ = ReadOnlyListExtensions
                                      .Where(wrapped, predicate)
                                      .ToList();

            // Assert
            _ = action.Must()
                .Throw <ArgumentNullException>()
                .EvaluateTrue(exception => exception.ParamName == "predicate");
        }
Пример #29
0
        public void First_With_ValidData_Must_Return_Some(int[] source)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList <int>(source);
            var expected = Enumerable
                           .First(source);

            // Act
            var result = ReadOnlyListExtensions
                         .First <Wrap.ReadOnlyListWrapper <int>, int>(wrapped);

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Пример #30
0
        public void ToList_SelectorAt_With_Null_Must_Throw()
        {
            // Arrange
            var source   = new int[0];
            var wrapped  = Wrap.AsReadOnlyList(source);
            var selector = (NullableSelectorAt <int, string>)null;

            // Act
            Action action = () => _ = ReadOnlyListExtensions
                                      .Select(wrapped, selector)
                                      .ToList();

            // Assert
            _ = action.Must()
                .Throw <ArgumentNullException>()
                .EvaluateTrue(exception => exception.ParamName == "selector");
        }