Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Apr 13, 2023
2 parents a23be6d + 0ae3772 commit af6534d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- X10D: Added math-related extension methods for `BigInteger`.
- X10D: Added `Span<T>.Replace(T, T)`.
- X10D: Added `CountDigits` for integer types.
- X10D: Added `Progress<T>.OnProgressChanged([T])`;
- X10D: Added `IEnumerable<T>.Except(T)`.
- X10D: Added `Progress<T>.OnProgressChanged([T])`.
- X10D: Added `TextWriter.WriteNoAlloc(int[, ReadOnlySpan<char>[, IFormatProvider]])`.
- X10D: Added `TextWriter.WriteNoAlloc(uint[, ReadOnlySpan<char>[, IFormatProvider]])`.
- X10D: Added `TextWriter.WriteNoAlloc(long[, ReadOnlySpan<char>[, IFormatProvider]])`.
Expand Down
25 changes: 25 additions & 0 deletions X10D.Tests/src/Linq/EnumerableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ public void ConcatOne_ShouldThrowArgumentNullException_GivenNullSource()
Assert.Throws<ArgumentNullException>(() => source!.ConcatOne("Foobar").ToArray());
}

[Test]
public void Except_ShouldFilterElements_GivenMatchingElements()
{
int[] source = Enumerable.Range(1, 10).ToArray();
int[] result = source.Except(5).ToArray();

Assert.That(result, Is.EquivalentTo(new[] {1, 2, 3, 4, 6, 7, 8, 9, 10}));
}

[Test]
public void Except_ShouldReturnSameElements_GivenNoMatchingElements()
{
int[] source = Enumerable.Range(1, 10).ToArray();
int[] result = source.Except(11).ToArray();

Assert.That(result, Is.EquivalentTo(source));
}

[Test]
public void Except_ShouldThrowArgumentNullException_GivenNullSource()
{
IEnumerable<int> source = null!;
Assert.Throws<ArgumentNullException>(() => source.Except(42));
}

[Test]
public void MinMax_ShouldReturnCorrectValues_UsingDefaultComparer()
{
Expand Down
5 changes: 4 additions & 1 deletion X10D/src/Collections/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ public static IReadOnlyCollection<T> Shuffled<T>(this IEnumerable<T> source, Ran
/// <returns>
/// An <see cref="IEnumerable{T}" /> that contains elements from the input sequence that do not satisfy the condition.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> or <paramref name="predicate" /> is null.</exception>
/// <exception cref="ArgumentNullException">
/// <paramref name="source" /> or <paramref name="predicate" /> is <see langword="null" />.
/// </exception>
[Pure]
public static IEnumerable<TSource> WhereNot<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
Expand Down Expand Up @@ -381,6 +383,7 @@ public static IEnumerable<TSource> WhereNot<TSource>(this IEnumerable<TSource> s
/// An <see cref="IEnumerable{T}" /> that contains elements from the input sequence that are not <see langword="null" />
/// (<see langword="Nothing" /> in Visual Basic).
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource?> source)
{
#if NET6_0_OR_GREATER
Expand Down
25 changes: 25 additions & 0 deletions X10D/src/Linq/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ public static IEnumerable<TSource> ConcatOne<TSource>(this IEnumerable<TSource>
yield return value;
}

/// <summary>
/// Filters a sequence of values by omitting elements that match a specified value.
/// </summary>
/// <param name="source">An <see cref="IEnumerable{T}" /> to filter.</param>
/// <param name="item">The value to omit.</param>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <returns>
/// An <see cref="IEnumerable{T}" /> that contains elements from the input sequence that do not match the specified
/// value.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> source, TSource item)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

return source.Where(i => !Equals(i, item));
}

/// <summary>
/// Returns the minimum and maximum values in a sequence of values.
/// </summary>
Expand Down

0 comments on commit af6534d

Please sign in to comment.