public void ElementAt_Skip_Take_PredicateAt_With_ValidData_Must_Return_Some(int[] source, int skipCount, int takeCount, PredicateAt <int> predicate) { // Arrange var wrapped = Wrap.AsReadOnlyList(source); var expected = Enumerable .Skip(source, skipCount) .Take(takeCount) .Where(predicate.AsFunc()) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act var result = ReadOnlyListExtensions .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skipCount) .Take(takeCount) .Where(predicate) .ElementAt(index); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected[index]), () => throw new Exception()); } }
public void WhereRef_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = Enumerable .Where(source, predicate.AsFunc()); // Act var result = ArrayExtensions .WhereRef(source.AsSpan(), predicate); // Assert _ = result.SequenceEqual(expected).Must().BeTrue(); }
public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = Enumerable .Where(source, predicate.AsFunc()) .Count() == source.Length; // Act var result = ArrayExtensions .All(source, predicate); // Assert _ = result.Must() .BeEqualTo(expected); }
public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = System.Linq.Enumerable.Count( System.Linq.Enumerable.Where(source, predicate.AsFunc())) == source.Length; // Act var result = ArrayExtensions .All <int>((ReadOnlyMemory <int>)source.AsMemory(), predicate); // Assert _ = result.Must() .BeEqualTo(expected); }
public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = System.Linq.Enumerable.Count( System.Linq.Enumerable.Where(source, predicate.AsFunc())) != 0; // Act var result = ArrayExtensions .Any <int>(source.AsSpan(), predicate); // Assert _ = result.Must() .BeEqualTo(expected); }
public void WhereRef_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = Enumerable .Where(source, predicate.AsFunc()); // Act var result = ArrayExtensions .WhereRef(source, predicate); // Assert _ = result.Must() .BeEnumerableOf <int>() .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); _ = result.SequenceEqual(expected).Must().BeTrue(); }
public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = Enumerable .Where(source, predicate.AsFunc()) .Count(); // Act var result = ArrayExtensions .Where((ReadOnlySpan <int>)source.AsSpan(), predicate) .Count(); // Assert _ = result.Must() .BeEqualTo(expected); }
public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); var expected = System.Linq.Enumerable.Count( System.Linq.Enumerable.Where(source, predicate.AsFunc())) != 0; // Act var result = ValueEnumerable .Any <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int>(wrapped, predicate); // Assert _ = result.Must() .BeEqualTo(expected); }
public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = System.Linq.Enumerable.Count( System.Linq.Enumerable.Where(source, predicate.AsFunc())); // Act var result = Array .Where <int>(source.AsMemory(), predicate) .Count(); // Assert _ = result.Must() .BeEqualTo(expected); }
public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var wrapped = Wrap.AsValueReadOnlyList(source); var expected = System.Linq.Enumerable.Any( System.Linq.Enumerable.Where(source, predicate.AsFunc())); // Act var result = ReadOnlyListExtensions .Any <Wrap.ValueReadOnlyListWrapper <int>, int>(wrapped, predicate); // Assert _ = result.Must() .BeEqualTo(expected); }
public void Contains_PredicateAt_With_Comparer_And_Contains_Must_ReturnTrue(int[] source, PredicateAt <int> predicate) { // Arrange var value = System.Linq.Enumerable.Last( System.Linq.Enumerable.Where(source, predicate.AsFunc())); // Act var result = Array .Where <int>((ReadOnlySpan <int>)source.AsSpan(), predicate) .Contains(value, EqualityComparer <int> .Default); // Assert _ = result.Must() .BeTrue(); }
public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); var expected = System.Linq.Enumerable.Count( System.Linq.Enumerable.Where(source, predicate.AsFunc())) == source.Length; // Act var result = ValueReadOnlyCollectionExtensions .All <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate); // Assert _ = result.Must() .BeEqualTo(expected); }
public async ValueTask AnyAsync_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); var expected = System.Linq.Enumerable.Count( System.Linq.Enumerable.Where(source, predicate.AsFunc())) != 0; // Act var result = await AsyncValueEnumerableExtensions .AnyAsync <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int>(wrapped, predicate.AsAsync()); // Assert _ = result.Must() .BeEqualTo(expected); }
public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var list = source.ToList(); var expected = Enumerable .Where(source, predicate.AsFunc()) .Count() != 0; // Act var result = ListBindings .Any(list, predicate); // Assert _ = result.Must() .BeEqualTo(expected); }
public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var pool = MemoryPool <int> .Shared; var expected = Enumerable .Where(source, predicate.AsFunc()) .ToArray(); // Act using var result = ArrayExtensions .Where((ReadOnlyMemory <int>)source.AsMemory(), predicate) .ToArray(pool); // Assert _ = result.Memory.Must() .BeEqualTo(expected); }
public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, PredicateAt <int> predicate) { // Arrange var expected = Enumerable .Where(source, predicate.AsFunc()) .First(); // Act var result = ArrayExtensions .Where((ReadOnlySpan <int>)source.AsSpan(), predicate) .First(); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected), () => throw new Exception()); }
public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, PredicateAt <int> predicate) { // Arrange var expected = System.Linq.Enumerable.First( System.Linq.Enumerable.Where(source, predicate.AsFunc())); // Act var result = Array .Where <int>(source.AsMemory(), predicate) .First(); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected), () => throw new Exception()); }
public async ValueTask ContainsAsync_PredicateAt_With_Comparer_And_Contains_Must_ReturnTrue(int[] source, PredicateAt <int> predicate) { // Arrange var value = System.Linq.Enumerable.Last( System.Linq.Enumerable.Where(source, predicate.AsFunc())); var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act var result = await AsyncValueEnumerable .Where <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int>(wrapped, predicate.AsAsync()) .ContainsAsync(value, EqualityComparer <int> .Default); // Assert _ = result.Must() .BeTrue(); }
public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = Enumerable .Where(source, predicate.AsFunc()); // Act var result = AsyncValueEnumerableExtensions .Where <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int>(wrapped, predicate.AsAsync()); // Assert _ = result.Must() .BeAsyncEnumerableOf <int>() .BeEqualTo(expected); }
public void Where_PredicateAt_With_ValidData_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var list = source.ToList(); var expected = Enumerable .Where(source, predicate.AsFunc()); // Act var result = ListBindings .Where(list, predicate); // Assert _ = result.Must() .BeEnumerableOf <int>() .BeEqualTo(expected, testRefStructs: false); _ = result.SequenceEqual(expected).Must().BeTrue(); }
public void All_Skip_Take_PredicateAt_With_ValidData_Must_Succeed(int[] source, int skip, int take, PredicateAt <int> predicate) { // Arrange var(offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment <int>(source, offset, count); var expected = Enumerable .Where(wrapped, predicate.AsFunc()) .Count() == count; // Act var result = ArrayExtensions .All(wrapped, predicate); // Assert _ = result.Must() .BeEqualTo(expected); }
public void Contains_PredicateAt_With_Null_And_Contains_Must_ReturnTrue(int[] source, PredicateAt <int> predicate) { // Arrange var value = System.Linq.Enumerable.Last( System.Linq.Enumerable.Where(source, predicate.AsFunc())); var wrapped = Wrap.AsValueEnumerable(source); // Act var result = ValueEnumerable .Where <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int>(wrapped, predicate) .Contains(value, null); // Assert _ = result.Must() .BeTrue(); }
public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, PredicateAt <int> predicate) { // Arrange var expected = System.Linq.Enumerable.Single( System.Linq.Enumerable.Where(source, predicate.AsFunc())); // Act var result = Array .Where <int>((ReadOnlySpan <int>)source.AsSpan(), predicate) .Single(); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected), () => throw new Exception()); }
public void ToArray_With_PredicateAt_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = System.Linq.Enumerable.ToArray( System.Linq.Enumerable.Where(source, predicate.AsFunc())); // Act var result = Array .Where <int>((ReadOnlyMemory <int>)source.AsMemory(), predicate) .ToArray(); // Assert _ = result.Must() .BeArrayOf <int>() .BeEqualTo(expected); }
public void ToArray_With_PredicateAt_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = Enumerable .Where(source, predicate.AsFunc()) .ToArray(); // Act var result = ArrayExtensions .Where(source.AsMemory(), predicate) .ToArray(); // Assert _ = result.Must() .BeArrayOf <int>() .BeEqualTo(expected); }
public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, PredicateAt <int> predicate) { // Arrange var expected = Enumerable .Where(source, predicate.AsFunc()) .Single(); // Act var result = ArrayExtensions .Where(source.AsMemory(), predicate) .Single(); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected), () => throw new Exception()); }
public void ToArray_PredicateAt_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = Enumerable .Where(source, predicate.AsFunc()) .ToArray(); // Act var result = ArrayExtensions .Where((ReadOnlySpan <int>)source.AsSpan(), predicate) .ToArray(); // Assert _ = result.Must() .BeNotSameAs(source) .BeArrayOf <int>() .BeEqualTo(expected); }
public async ValueTask SingleAsync_PredicateAt_With_SingleAsync_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = System.Linq.Enumerable.Single( System.Linq.Enumerable.Where(source, predicate.AsFunc())); // Act var result = await AsyncValueEnumerable .Where <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int>(wrapped, predicate.AsAsync()) .SingleAsync(); // Assert _ = result.Must() .BeEqualTo(expected); }
public void ToList_With_PredicateAt_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var expected = System.Linq.Enumerable.ToList( System.Linq.Enumerable.Where(source, predicate.AsFunc())); // Act var result = Array .Where <int>((ReadOnlySpan <int>)source.AsSpan(), predicate) .ToList(); // Assert _ = result.Must() .BeOfType <List <int> >() .BeEnumerableOf <int>() .BeEqualTo(expected); }
public void Single_PredicateAt_With_Single_Must_Succeed(int[] source, PredicateAt <int> predicate) { // Arrange var wrapped = Wrap .AsValueReadOnlyList(source); var expected = System.Linq.Enumerable.Single( System.Linq.Enumerable.Where(source, predicate.AsFunc())); // Act var result = ReadOnlyList .Where <Wrap.ValueReadOnlyList <int>, int>(wrapped, predicate) .Single(); // Assert _ = result.Must() .BeEqualTo(expected); }