コード例 #1
0
        public void Contains_Selector_With_Comparer_And_Contains_Must_ReturnTrue(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var value =
                System.Linq.Enumerable.Last(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

            // Act
            var result = Array
                         .Select <int, string>((ReadOnlySpan <int>)source.AsSpan(), selector)
                         .Contains(value, EqualityComparer <string> .Default);

            // Assert
            _ = result.Must()
                .BeTrue();
        }
コード例 #2
0
        public void Contains_Selector_With_Null_And_Contains_Must_ReturnTrue(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var value =
                System.Linq.Enumerable.Last(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));
            var wrapped = Wrap.AsValueEnumerable(source);

            // Act
            var result = ValueEnumerable
                         .Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector)
                         .Contains(value, null);

            // Assert
            _ = result.Must()
                .BeTrue();
        }
コード例 #3
0
        public void ToArray_With_Selector_Must_Succeed(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var expected =
                System.Linq.Enumerable.ToArray(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

            // Act
            var result = Array
                         .Select <int, string>((ReadOnlyMemory <int>)source.AsMemory(), selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
        public void Contains_Selector_With_Comparer_And_Contains_Must_ReturnTrue(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var value =
                System.Linq.Enumerable.Last(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));
            var wrapped = Wrap.AsValueReadOnlyCollection(source);

            // Act
            var result = ValueReadOnlyCollection
                         .Select <Wrap.ValueReadOnlyCollection <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector)
                         .Contains(value, EqualityComparer <string> .Default);

            // Assert
            _ = result.Must()
                .BeTrue();
        }
コード例 #5
0
        public void Single_Selector_With_Single_Must_Return_Some(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var expected =
                System.Linq.Enumerable.Single(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

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

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
コード例 #6
0
        public async ValueTask ContainsAsync_Selector_With_Comparer_And_Contains_Must_ReturnTrue(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var value =
                System.Linq.Enumerable.Last(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));
            var wrapped = Wrap.AsAsyncValueEnumerable(source);

            // Act
            var result = await AsyncValueEnumerable
                         .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync())
                         .ContainsAsync(value, EqualityComparer <string> .Default);

            // Assert
            _ = result.Must()
                .BeTrue();
        }
コード例 #7
0
        public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var expected =
                System.Linq.Enumerable.First(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

            // Act
            var result = Array
                         .Select <int, string>((ReadOnlyMemory <int>)source.AsMemory(), selector)
                         .First();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
コード例 #8
0
        public void ToArray_With_Selector_Must_Succeed(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsValueReadOnlyList(source);
            var expected =
                System.Linq.Enumerable.ToArray(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

            // Act
            var result = ReadOnlyList
                         .Select <Wrap.ValueReadOnlyList <int>, int, string>(wrapped, selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
コード例 #9
0
        public void ToList_With_Selector_Must_Succeed(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var expected =
                System.Linq.Enumerable.ToList(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

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

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
コード例 #10
0
        public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsValueReadOnlyList(source);
            var expected =
                System.Linq.Enumerable.Select(
                    System.Linq.Enumerable.Where(wrapped, predicate.AsFunc()), selector.AsFunc());

            // Act
            var result = ReadOnlyList
                         .Where <Wrap.ValueReadOnlyList <int>, int>(wrapped, predicate)
                         .Select(selector);

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
コード例 #11
0
        public void Contains_Predicate_Selector_With_Null_And_Contains_Must_ReturnTrue(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var value =
                System.Linq.Enumerable.Last(
                    System.Linq.Enumerable.Select(
                        System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()));

            // Act
            var result = Array
                         .Where <int>((ReadOnlySpan <int>)source.AsSpan(), predicate)
                         .Select(selector)
                         .Contains(value, null);

            // Assert
            _ = result.Must()
                .BeTrue();
        }
コード例 #12
0
        public async ValueTask ContainsAsync_Predicate_Selector_With_Null_And_Contains_Must_ReturnTrue(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var value =
                System.Linq.Enumerable.Last(
                    System.Linq.Enumerable.Select(
                        System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()));
            var wrapped = Wrap.AsAsyncValueEnumerable(source);

            // Act
            var result = await AsyncValueEnumerable
                         .Where <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int>(wrapped, predicate.AsAsync())
                         .Select(selector.AsAsync())
                         .ContainsAsync(value, null);

            // Assert
            _ = result.Must()
                .BeTrue();
        }
        public async ValueTask ToArrayAsync_Selector_With_ValidData_Must_Succeed(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsAsyncValueEnumerable(source);
            var expected =
                System.Linq.Enumerable.ToArray(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

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

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
コード例 #14
0
        public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var expected =
                System.Linq.Enumerable.First(
                    System.Linq.Enumerable.Select(
                        System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()));

            // Act
            var result = Array
                         .Where <int>(source.AsSpan(), predicate)
                         .Select(selector)
                         .First();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
コード例 #15
0
        public void ForEach_ActionAt_Selector_With_ValidData_Must_Succeed(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var result   = new List <(string, int)>();
            var expected = new List <(string, int)>();

            System.Linq.EnumerableEx.ForEach(
                System.Linq.Enumerable.Select(source, selector.AsFunc()), (item, index) => expected.Add((item, index)));

            // Act
            Array
            .Select <int, string>((ReadOnlySpan <int>)source.AsSpan(), selector)
            .ForEach((item, index) => result.Add((item, index)));

            // Assert
            _ = result.Must()
                .BeEnumerableOf <(string, int)>()
                .BeEqualTo(expected);
        }
コード例 #16
0
        public void ToArray_With_Predicate_Selector_Must_Succeed(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var expected =
                System.Linq.Enumerable.ToArray(
                    System.Linq.Enumerable.Select(
                        System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()));

            // Act
            var result = Array
                         .Where <int>((ReadOnlySpan <int>)source.AsSpan(), predicate)
                         .Select(selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
コード例 #17
0
        public void Contains_Predicate_Selector_With_Comparer_And_Contains_Must_ReturnTrue(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var value =
                System.Linq.Enumerable.Last(
                    System.Linq.Enumerable.Select(
                        System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()));
            var wrapped = Wrap.AsValueEnumerable(source);

            // Act
            var result = ValueEnumerable
                         .Where <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .Select(selector)
                         .Contains(value, EqualityComparer <string> .Default);

            // Assert
            _ = result.Must()
                .BeTrue();
        }
コード例 #18
0
        public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected =
                System.Linq.Enumerable.First(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

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

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
コード例 #19
0
        public async ValueTask SingleAsync_Selector_With_SingleAsync_Must_Return_Some(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsAsyncValueEnumerable(source);
            var expected =
                System.Linq.Enumerable.Single(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

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

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
コード例 #20
0
        public void ForEach_Action_Selector_With_ValidData_Must_Succeed(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var result   = new List <string>();
            var expected = new List <string>();

            System.Linq.EnumerableEx.ForEach(
                System.Linq.Enumerable.Select(source, selector.AsFunc()), item => expected.Add(item));

            // Act
            Array
            .Select <int, string>(source.AsMemory(), selector)
            .ForEach(item => result.Add(item));

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
        public async ValueTask ForEachAsync_Action_Selector_With_ValidData_Must_Succeed(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsAsyncValueEnumerable(source);
            var result   = new List <string>();
            var expected = new List <string>();

            System.Linq.EnumerableEx.ForEach(
                System.Linq.Enumerable.Select(source, selector.AsFunc()), item => expected.Add(item));

            // Act
            await AsyncValueEnumerable
            .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync())
            .ForEachAsync((item, cancellationToken) => { result.Add(item); return(new ValueTask()); });

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
コード例 #22
0
        public void ForEach_Action_Selector_With_ValidData_Must_Succeed(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsValueEnumerable(source);
            var result   = new List <string>();
            var expected = new List <string>();

            System.Linq.EnumerableEx.ForEach(
                System.Linq.Enumerable.Select(source, selector.AsFunc()), item => expected.Add(item));

            // Act
            ValueEnumerable
            .Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector)
            .ForEach(item => result.Add(item));

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
コード例 #23
0
        public void ToList_Selector_With_ValidData_Must_Succeed(int[] source, Selector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected =
                System.Linq.Enumerable.ToList(
                    System.Linq.Enumerable.Select(source, selector.AsFunc()));

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

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
コード例 #24
0
        public void ToList_With_Predicate_Selector_Must_Succeed(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var expected =
                System.Linq.Enumerable.ToList(
                    System.Linq.Enumerable.Select(
                        System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()));

            // Act
            var result = Array
                         .Where <int>(source.AsMemory(), predicate)
                         .Select(selector)
                         .ToList();

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
コード例 #25
0
        public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Selector <int, string> selector)
        {
            for (var index = 0; index < source.Length; index++)
            {
                // Arrange
                var expected =
                    System.Linq.Enumerable.ElementAt(
                        System.Linq.Enumerable.Select(source, selector.AsFunc()), index);

                // Act
                var result = Array
                             .Select <int, string>(source, selector)
                             .ElementAt(index);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected),
                    () => throw new Exception());
            }
        }
コード例 #26
0
        public async ValueTask ElementAtAsync_Selector_With_ValidData_Must_Return_Some(int[] source, Selector <int, string> selector)
        {
            for (var index = 0; index < source.Length; index++)
            {
                // Arrange
                var wrapped  = Wrap.AsAsyncValueEnumerable(source);
                var expected =
                    System.Linq.Enumerable.ElementAt(
                        System.Linq.Enumerable.Select(source, selector.AsFunc()), index);

                // Act
                var result = await AsyncValueEnumerable
                             .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync())
                             .ElementAtAsync(index);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected),
                    () => throw new Exception());
            }
        }
コード例 #27
0
        public void ToArray_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected =
                System.Linq.Enumerable.ToArray(
                    System.Linq.Enumerable.Select(
                        System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()));

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

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
コード例 #28
0
        public void ForEach_ActionAt_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var result   = new List <(string, int)>();
            var expected = new List <(string, int)>();

            System.Linq.EnumerableEx.ForEach(
                System.Linq.Enumerable.Select(
                    System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()), (item, index) => expected.Add((item, index)));

            // Act
            Array
            .Where <int>(source.AsMemory(), predicate)
            .Select(selector)
            .ForEach((item, index) => result.Add((item, index)));

            // Assert
            _ = result.Must()
                .BeEnumerableOf <(string, int)>()
                .BeEqualTo(expected);
        }
コード例 #29
0
        public void ForEach_Action_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var result   = new List <string>();
            var expected = new List <string>();

            System.Linq.EnumerableEx.ForEach(
                System.Linq.Enumerable.Select(
                    System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()), item => expected.Add(item));

            // Act
            Array
            .Where <int>((ReadOnlySpan <int>)source.AsSpan(), predicate)
            .Select(selector)
            .ForEach(item => result.Add(item));

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
コード例 #30
0
        public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected =
                System.Linq.Enumerable.Single(
                    System.Linq.Enumerable.Select(
                        System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()));

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

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }