Example #1
0
        public void Single_Predicate_With_Empty_Must_Return_None(int[] source, Func <int, bool> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);

            // Act
            var result = ValueEnumerableExtensions
                         .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .Single();

            // Assert
            _ = result.Must()
                .BeOfType <Option <int> >()
                .EvaluateTrue(option => option.IsNone);
        }
        public void Where_Predicate_With_Null_Must_Throw()
        {
            // Arrange
            var enumerable = Wrap
                             .AsValueEnumerable(new int[0]);
            var predicate = (Predicate <int>)null;

            // Act
            Action action = () => _ = ValueEnumerableExtensions
                                      .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(enumerable, predicate);

            // Assert
            _ = action.Must()
                .Throw <ArgumentNullException>()
                .EvaluateTrue(exception => exception.ParamName == "predicate");
        }
        public void Where_With_ValidData_Must_Succeed(int[] source, Func <int, int, bool> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Where(wrapped, predicate);

            // Act
            var result = ValueEnumerableExtensions
                         .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate);

            // Assert
            _ = result.Must()
                .BeEnumerableOf <int>()
                .BeEqualTo(expected);
        }
        public void Single_Predicate_Selector_With_Multiple_Must_Return_None(int[] source, Predicate <int> predicate, NullableSelector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);

            // Act
            var result = ValueEnumerableExtensions
                         .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .Select(selector)
                         .Single();

            // Assert
            _ = result.Must()
                .BeOfType <Option <string> >()
                .EvaluateTrue(option => option.IsNone);
        }
Example #5
0
        public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Count(source, predicate.AsFunc());

            // Act
            var result = ValueEnumerableExtensions
                         .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .Count();

            // Assert
            _ = result.Must()
                .BeEqualTo(expected);
        }
        public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func <int, bool> predicate, Func <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsValueEnumerable(source);
            var expected =
                System.Linq.Enumerable.Select(
                    System.Linq.Enumerable.Where(wrapped, predicate), selector);

            // Act
            var result = ValueEnumerableExtensions
                         .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .Select(selector);

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
Example #7
0
        public void Single_Predicate_With_Single_Must_Return_Some(int[] source, Func <int, bool> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Single(source, predicate);

            // Act
            var result = ValueEnumerableExtensions
                         .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .Single();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Example #8
0
        public void ToArray_PredicateAt_MemoryPool_With_ValidData_Must_Succeed(int[] source, Func <int, int, bool> predicate)
        {
            // Arrange
            var pool    = MemoryPool <int> .Shared;
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Where(source, predicate)
                           .ToArray();

            // Act
            using var result = ValueEnumerableExtensions
                               .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                               .ToArray(pool);

            // Assert
            _ = result.Memory
                .SequenceEqual(expected);
        }
        public void ToArray_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected =
                System.Linq.Enumerable.ToArray(
                    System.Linq.Enumerable.Where(source, predicate.AsFunc()));

            // Act
            var result = ValueEnumerableExtensions
                         .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeArrayOf <int>()
                .BeEqualTo(expected);
        }
        public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, PredicateAt <int> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Where(source, predicate.AsFunc())
                           .First();

            // Act
            var result = ValueEnumerableExtensions
                         .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .First();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Example #11
0
        public void ToArray_Predicate_Selector_MemoryPool_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate, NullableSelector <int, string> selector)
        {
            // Arrange
            var pool    = MemoryPool <string> .Shared;
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Where(source, predicate.AsFunc())
                           .Select(selector.AsFunc())
                           .ToArray();

            // Act
            using var result = ValueEnumerableExtensions
                               .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                               .Select(selector)
                               .ToArray(pool);

            // Assert
            _ = result.Memory
                .SequenceEqual(expected);
        }
Example #12
0
        public void ToArray_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate, NullableSelector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Where(source, predicate.AsFunc())
                           .Select(selector.AsFunc())
                           .ToArray();

            // Act
            var result = ValueEnumerableExtensions
                         .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .Select(selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
Example #13
0
        public void ElementAt_Predicate_With_ValidData_Must_Return_Some(int[] source, Func <int, bool> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Where(source, predicate)
                           .ToList();

            for (var index = 0; index < expected.Count; index++)
            {
                // Act
                var result = ValueEnumerableExtensions
                             .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                             .ElementAt(index);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected[index]),
                    () => throw new Exception());
            }
        }
Example #14
0
        public void ElementAt_Predicate_With_OutOfRange_Must_Return_None(int[] source, Func <int, bool> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);

            // Act
            var optionNegative = ValueEnumerableExtensions
                                 .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                                 .ElementAt(-1);
            var optionTooLarge = ValueEnumerableExtensions
                                 .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                                 .ElementAt(source.Length);

            // Assert
            _ = optionNegative.Must()
                .BeOfType <Option <int> >()
                .EvaluateTrue(option => option.IsNone);
            _ = optionTooLarge.Must()
                .BeOfType <Option <int> >()
                .EvaluateTrue(option => option.IsNone);
        }