Skip to content

Commit

Permalink
Merge a14843f into 35fefdf
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz authored Jul 4, 2023
2 parents 35fefdf + a14843f commit d891ea1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
11 changes: 6 additions & 5 deletions MoreLinq.Test/AssertTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,31 @@ public void AssertIsLazy()
[Test]
public void AssertSequenceWithValidAllElements()
{
var source = new[] { 2, 4, 6, 8 };
source.Assert(n => n % 2 == 0).AssertSequenceEqual(source);
var xs = new[] { 2, 4, 6, 8 };
using var source = TestingSequence.Of(xs);
source.Assert(n => n % 2 == 0).AssertSequenceEqual(xs);
}

[Test]
public void AssertSequenceWithValidSomeInvalidElements()
{
var source = new[] { 2, 4, 6, 7, 8, 9 };
using var source = TestingSequence.Of(2, 4, 6, 7, 8, 9);
Assert.That(() => source.Assert(n => n % 2 == 0).Consume(),
Throws.InvalidOperationException);
}

[Test]
public void AssertSequenceWithInvalidElementsAndCustomErrorReturningNull()
{
var source = new[] { 2, 4, 6, 7, 8, 9 };
using var source = TestingSequence.Of(2, 4, 6, 7, 8, 9);
Assert.That(() => source.Assert(n => n % 2 == 0, _ => null!).Consume(),
Throws.InvalidOperationException);
}

[Test]
public void AssertSequenceWithInvalidElementsAndCustomError()
{
var source = new[] { 2, 4, 6, 7, 8, 9 };
using var source = TestingSequence.Of(2, 4, 6, 7, 8, 9);
Assert.That(() =>
source.Assert(n => n % 2 == 0, n => new ValueException(n)).Consume(),
Throws.TypeOf<ValueException>()
Expand Down
10 changes: 8 additions & 2 deletions MoreLinq.Test/AtLeastTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace MoreLinq.Test
{
using System;
using NUnit.Framework;
using System.Collections.Generic;

Expand Down Expand Up @@ -49,8 +50,13 @@ from e in new[]
.SetName($"{{m}}({k}[{e.Size}], {e.Count})");

[TestCaseSource(nameof(AtLeastSource))]
public bool AtLeast(SourceKind sourceKind, int sequenceSize, int atLeastAssertCount) =>
Enumerable.Range(0, sequenceSize).ToSourceKind(sourceKind).AtLeast(atLeastAssertCount);
public bool AtLeast(SourceKind sourceKind, int sequenceSize, int atLeastAssertCount)
{
var xs = Enumerable.Range(0, sequenceSize);
var source = xs.ToSourceKind(sourceKind);
using (source as IDisposable) // primarily for `TestingSequence<>`
return source.AtLeast(atLeastAssertCount);
}

[Test]
public void AtLeastDoesNotIterateUnnecessaryElements()
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq.Test/TestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ internal static IEnumerable<T> ToSourceKind<T>(this IEnumerable<T> input, Source
sourceKind switch
#pragma warning restore IDE0072 // Add missing cases
{
SourceKind.Sequence => input.Select(x => x),
SourceKind.Sequence => input.AsTestingSequence(),
var kind => input.ToList().AsSourceKind(kind)
};

internal static IEnumerable<T> AsSourceKind<T>(this List<T> input, SourceKind sourceKind) =>
sourceKind switch
{
SourceKind.Sequence => input.Select(x => x),
SourceKind.Sequence => input.AsTestingSequence(),
SourceKind.BreakingList => new BreakingList<T>(input),
SourceKind.BreakingReadOnlyList => new BreakingReadOnlyList<T>(input),
SourceKind.BreakingCollection => new BreakingCollection<T>(input),
Expand Down

0 comments on commit d891ea1

Please sign in to comment.