public void ElementAt_Skip_Take_SelectorAt_With_ValidData_Must_Return_Some(int[] source, int skipCount, int takeCount, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Select(selector.AsFunc())
                           .ToList();

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

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected[index]),
                    () => throw new Exception());
            }
        }
Exemple #2
0
        public void Select_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var expected =
                System.Linq.Enumerable.Select(source, selector.AsFunc());

            // Act
            var result = ArrayExtensions.Select((ReadOnlySpan <int>)source.AsSpan(), selector);

            // Assert
            _ = result.SequenceEqual(expected).Must().BeTrue();
        }
        public void Select_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var expected =
                System.Linq.Enumerable.Select(source, selector.AsFunc());

            // Act
            var result = ArrayExtensions.Select(source.AsMemory(), selector);

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected, testRefStructs: false);
            _ = result.SequenceEqual(expected).Must().BeTrue();
        }
Exemple #4
0
        public void Select_Selector_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsAsyncValueEnumerable(source);
            var expected = System.Linq.Enumerable
                           .Select(source, selector.AsFunc());

            // Act
            var result = AsyncValueEnumerableExtensions
                         .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync());

            // Assert
            _ = result.Must()
                .BeAsyncEnumerableOf <string>()
                .BeEqualTo(expected);
        }
        public void ToArray_With_SelectorAt_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .ToArray();

            // Act
            var result = ArrayExtensions
                         .Select(source.AsMemory(), selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
        public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .Single();

            // Act
            var result = ArrayExtensions
                         .Select <int, string>(source.AsMemory(), selector)
                         .Single();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Exemple #7
0
        public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .First();

            // Act
            var result = ArrayExtensions
                         .Select((ReadOnlySpan <int>)source.AsSpan(), selector)
                         .First();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Exemple #8
0
        public void ToArray_With_SelectorAt_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var expected =
                System.Linq.Enumerable.ToArray(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

            // Act
            var result = ArrayExtensions
                         .Select <int, string>((ReadOnlySpan <int>)source.AsSpan(), selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
        public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var pool     = MemoryPool <string> .Shared;
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .ToArray();

            // Act
            using var result = ArrayExtensions
                               .Select((ReadOnlyMemory <int>)source.AsMemory(), selector)
                               .ToArray(pool);

            // Assert
            _ = result.Memory.Must()
                .BeEqualTo(expected);
        }
Exemple #10
0
        public void Select_SelectorAt_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var list     = source.ToList();
            var expected = Enumerable
                           .Select(source, selector.AsFunc());

            // Act
            var result = ListBindings
                         .Select(list, selector);

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected, testRefStructs: false);
            _ = result.SequenceEqual(expected).Must().BeTrue();
        }
Exemple #11
0
        public void ToList_With_SelectorAt_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .ToList();

            // Act
            var result = ArrayExtensions
                         .Select((ReadOnlySpan <int>)source.AsSpan(), selector)
                         .ToList();

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
Exemple #12
0
        public void Select_With_ValidData_Must_Succeed(int[] source, int skip, int take, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var(offset, count) = Utils.SkipTake(source.Length, skip, take);
            var wrapped  = new ArraySegment <int>(source, offset, count);
            var expected = Enumerable
                           .Select(wrapped, selector.AsFunc());

            // Act
            var result = ArrayExtensions
                         .Select(wrapped, selector);

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected, testRefStructs: false);
            _ = result.SequenceEqual(expected).Must().BeTrue();
        }
Exemple #13
0
        public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueReadOnlyCollection(source);
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .First();

            // Act
            var result = ValueReadOnlyCollectionExtensions
                         .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector)
                         .First();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
        public void ToArray_SelectorAt_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueReadOnlyCollection(source);
            var expected =
                System.Linq.Enumerable.ToArray(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

            // Act
            var result = ValueReadOnlyCollectionExtensions
                         .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
Exemple #15
0
        public void ToArray_SelectorAt_MemoryPool_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var pool    = MemoryPool <string> .Shared;
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .ToArray();

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

            // Assert
            _ = result.Memory
                .SequenceEqual(expected);
        }
Exemple #16
0
        public async ValueTask ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var pool    = MemoryPool <string> .Shared;
            var wrapped = Wrap
                          .AsAsyncValueEnumerable(source);
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .ToArray();

            // Act
            var result = await AsyncValueEnumerableExtensions
                         .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync())
                         .ToArrayAsync(pool);

            // Assert
            _ = result.Memory
                .SequenceEqual(expected);
        }
Exemple #17
0
        public async ValueTask ToArrayAsync_SelectorAt_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsAsyncValueEnumerable(source);
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .ToArray();

            // Act
            var result = await AsyncValueEnumerableExtensions
                         .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync())
                         .ToArrayAsync();

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
        public async ValueTask FirstAsync_SelectorAt_With_ValidData_Must_Return_Some(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsAsyncValueEnumerable(source);
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .First();

            // Act
            var result = await AsyncValueEnumerableExtensions
                         .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync())
                         .FirstAsync();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Exemple #19
0
        public void ToArray_SelectorAt_Must_Succeed(int[] source, int skip, int take, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var(offset, count) = Utils.SkipTake(source.Length, skip, take);
            var wrapped  = new ArraySegment <int>(source, offset, count);
            var expected = Enumerable
                           .Select(wrapped, selector.AsFunc())
                           .ToArray();

            // Act
            var result = ArrayExtensions
                         .Select(wrapped, selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeNotSameAs(source)
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
        public void ToList_SelectorAt_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .ToList();

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

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
Exemple #21
0
        public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, int skip, int take, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var pool = MemoryPool <string> .Shared;

            var(offset, count) = Utils.SkipTake(source.Length, skip, take);
            var wrapped  = new ArraySegment <int>(source, offset, count);
            var expected = Enumerable
                           .Select(wrapped, selector.AsFunc())
                           .ToArray();

            // Act
            var result = ArrayExtensions
                         .Select(wrapped, selector)
                         .ToArray(pool);

            // Assert
            _ = result.Memory
                .SequenceEqual(expected);
        }
Exemple #22
0
        public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .ToList();

            for (var index = 0; index < source.Length; index++)
            {
                // Act
                var result = ArrayExtensions
                             .Select((ReadOnlyMemory <int>)source.AsMemory(), selector)
                             .ElementAt(index);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected[index]),
                    () => throw new Exception());
            }
        }
Exemple #23
0
        public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, int skipCount, int takeCount, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Select(selector.AsFunc())
                           .First();

            // Act
            var result = ArrayExtensions
                         .Skip(source, skipCount)
                         .Take(takeCount)
                         .Select(selector)
                         .First();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Exemple #24
0
        public void ToList_With_SelectorAt_Must_Succeed(int[] source, int skipCount, int takeCount, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Select(selector.AsFunc())
                           .ToList();

            // Act
            var result = ArrayExtensions
                         .Skip(source, skipCount)
                         .Take(takeCount)
                         .Select(selector)
                         .ToList();

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
        public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, int skip, int take, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var pool     = MemoryPool <string> .Shared;
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .Select(selector.AsFunc())
                           .ToArray();

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

            // Assert
            _ = result.Memory
                .SequenceEqual(expected);
        }
        public void ToArray_Skip_Take_SelectorAt_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsValueReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Select(selector.AsFunc())
                           .ToArray();

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ValueReadOnlyListWrapper <int>, int>(wrapped, skipCount)
                         .Take(takeCount)
                         .Select(selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
        public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, int skip, int take, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped  = new ArraySegment <int>(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .Select(selector.AsFunc())
                           .Single();

            // Act
            var result = ArrayExtensions
                         .Skip(wrapped, skip)
                         .Take(take)
                         .Select(selector)
                         .Single();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
        public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .ToList();

            for (var index = 0; index < source.Length; index++)
            {
                // Act
                var result = ValueEnumerableExtensions
                             .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector)
                             .ElementAt(index);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected[index]),
                    () => throw new Exception());
            }
        }
Exemple #29
0
        public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, int skip, int take, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList <int>(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .Select(selector.AsFunc())
                           .First();

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

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Exemple #30
0
        public void ToList_SelectorAt_Must_Succeed(int[] source, int skip, int take, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped  = new ArraySegment <int>(source);
            var expected = Enumerable
                           .Skip(wrapped, skip)
                           .Take(take)
                           .Select(selector.AsFunc())
                           .ToList();

            // Act
            var result = ArrayExtensions
                         .Skip(wrapped, skip)
                         .Take(take)
                         .Select(selector)
                         .ToList();

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }