Skip to content

Commit

Permalink
Fix code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin committed Nov 26, 2023
1 parent 172dbf8 commit a3c112c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Source/SuperLinq/Permutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public static IEnumerable<IList<T>> Permutations<T>(this IEnumerable<T> sequence
{
ArgumentNullException.ThrowIfNull(sequence);

if (sequence.TryGetCollectionCount() is int count
&& count > 21)
if (sequence.TryGetCollectionCount() is int and > 21)
{
ThrowHelper.ThrowArgumentException(nameof(sequence), "Input set is too large to permute properly.");
}
Expand Down
22 changes: 15 additions & 7 deletions Tests/SuperLinq.Test/PermutationsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ public void TestCardinalityZeroPermutation()
permutations.Single().AssertSequenceEqual();
}

[Fact]
public void TestExceptionWhenTooLong()
public static IEnumerable<object[]> GetTooLongSequences() =>
Enumerable.Range(1, 22)
.GetBreakingCollectionSequences()
.Select(x => new object[] { x, });

[Theory]
[MemberData(nameof(GetTooLongSequences))]
public void TestExceptionWhenTooLong(IDisposableEnumerable<int> seq)
{
using var emptySet = Enumerable.Range(1, 22).AsTestingSequence();

var result = emptySet.Permutations();
using (seq)
{
var ex = Assert.Throws<ArgumentException>(
"sequence",
() => seq.Permutations().Consume());

var ex = Assert.Throws<ArgumentException>("sequence", result.Consume);
Assert.Equal("Input set is too large to permute properly. (Parameter 'sequence')", ex.Message);
Assert.Equal("Input set is too large to permute properly. (Parameter 'sequence')", ex.Message);
}
}

/// <summary>
Expand Down

0 comments on commit a3c112c

Please sign in to comment.