Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NUnit.Analyzers, addressing warnings #910

Merged
merged 1 commit into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MoreLinq.Test/AssertCountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void AssertCountWithCollectionIsLazy()
public void AssertCountWithMatchingCollectionCount()
{
var xs = new[] { 123, 456, 789 };
Assert.AreSame(xs, xs.AssertCount(3));
Assert.That(xs, Is.SameAs(xs.AssertCount(3)));
}

[TestCase(3, 2, "Sequence contains too many elements when exactly 2 were expected.")]
Expand All @@ -122,7 +122,7 @@ public void AssertCountWithMismatchingCollectionCount(int sourceCount, int count
var xs = new int[sourceCount];
using var enumerator = xs.AssertCount(count).GetEnumerator();
var e = Assert.Throws<SequenceException>(() => enumerator.MoveNext());
Assert.AreEqual(e.Message, message);
Assert.That(e.Message, Is.EqualTo(message));
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq.Test/AssertTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void AssertSequenceWithInvalidElementsAndCustomError()
var e =
Assert.Throws<ValueException>(() =>
new[] { 2, 4, 6, 7, 8, 9 }.Assert(n => n % 2 == 0, n => new ValueException(n)).Consume());
Assert.AreEqual(7, e.Value);
Assert.That(e.Value, Is.EqualTo(7));
}

class ValueException : Exception
Expand Down
12 changes: 6 additions & 6 deletions MoreLinq.Test/CartesianTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void TestCartesianProductCount()

var result = sequenceA.Cartesian(sequenceB, (a, b) => a + b);

Assert.AreEqual(expectedCount, result.Count() );
Assert.That(result.Count(), Is.EqualTo(expectedCount));
}

/// <summary>
Expand All @@ -111,7 +111,7 @@ public void TestCartesianProductCount_Multidimensional()
var result = sequenceA.Cartesian(sequenceB, sequenceC, sequenceD, (a, b, c, d) => a + b + c + d);

const int expectedCount = countA * countB * countC * countD;
Assert.AreEqual(expectedCount, result.Count());
Assert.That(result.Count(), Is.EqualTo(expectedCount));
}

/// <summary>
Expand Down Expand Up @@ -139,7 +139,7 @@ public void TestCartesianProductCombinations()
.ToArray();

// verify that the expected number of results is correct
Assert.AreEqual(sequenceA.Count() * sequenceB.Count(), result.Count());
Assert.That(result.Count(), Is.EqualTo(sequenceA.Count() * sequenceB.Count()));

// ensure that all "cells" were visited by the cartesian product
foreach (var coord in result)
Expand All @@ -160,9 +160,9 @@ public void TestEmptyCartesianEvaluation()
var resultB = Enumerable.Empty<int>().Cartesian(sequence, (a, b) => new { A = a, B = b });
var resultC = Enumerable.Empty<int>().Cartesian(Enumerable.Empty<int>(), (a, b) => new { A = a, B = b });

Assert.AreEqual(0, resultA.Count());
Assert.AreEqual(0, resultB.Count());
Assert.AreEqual(0, resultC.Count());
Assert.That(resultA.Count(), Is.Zero);
Assert.That(resultB.Count(), Is.Zero);
Assert.That(resultC.Count(), Is.Zero);
}
}
}
24 changes: 12 additions & 12 deletions MoreLinq.Test/CompareCountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void CompareCountWithCollectionAndSequence(int collectionCount,

using var seq = Enumerable.Range(0, sequenceCount).AsTestingSequence();

Assert.AreEqual(expectedCompareCount, collection.CompareCount(seq));
Assert.AreEqual(expectedMoveNextCallCount, seq.MoveNextCallCount);
Assert.That(collection.CompareCount(seq), Is.EqualTo(expectedCompareCount));
Assert.That(seq.MoveNextCallCount, Is.EqualTo(expectedMoveNextCallCount));
}

[TestCase(0, 0, 0, 1)]
Expand All @@ -74,8 +74,8 @@ public void CompareCountWithSequenceAndCollection(int sequenceCount,

using var seq = Enumerable.Range(0, sequenceCount).AsTestingSequence();

Assert.AreEqual(expectedCompareCount, seq.CompareCount(collection));
Assert.AreEqual(expectedMoveNextCallCount, seq.MoveNextCallCount);
Assert.That(seq.CompareCount(collection), Is.EqualTo(expectedCompareCount));
Assert.That(seq.MoveNextCallCount, Is.EqualTo(expectedMoveNextCallCount));
}

[TestCase(0, 0, 0, 1)]
Expand All @@ -90,9 +90,9 @@ public void CompareCountWithSequenceAndSequence(int sequenceCount1,
using var seq1 = Enumerable.Range(0, sequenceCount1).AsTestingSequence();
using var seq2 = Enumerable.Range(0, sequenceCount2).AsTestingSequence();

Assert.AreEqual(expectedCompareCount, seq1.CompareCount(seq2));
Assert.AreEqual(expectedMoveNextCallCount, seq1.MoveNextCallCount);
Assert.AreEqual(expectedMoveNextCallCount, seq2.MoveNextCallCount);
Assert.That(seq1.CompareCount(seq2), Is.EqualTo(expectedCompareCount));
Assert.That(seq1.MoveNextCallCount, Is.EqualTo(expectedMoveNextCallCount));
Assert.That(seq2.MoveNextCallCount, Is.EqualTo(expectedMoveNextCallCount));
}

[Test]
Expand All @@ -101,7 +101,7 @@ public void CompareCountDisposesSequenceEnumerators()
using var seq1 = TestingSequence.Of<int>();
using var seq2 = TestingSequence.Of<int>();

Assert.AreEqual(0, seq1.CompareCount(seq2));
Assert.That(seq1.CompareCount(seq2), Is.Zero);
}

[Test]
Expand All @@ -111,7 +111,7 @@ public void CompareCountDisposesFirstEnumerator()

using var seq = TestingSequence.Of<int>();

Assert.AreEqual(0, seq.CompareCount(collection));
Assert.That(seq.CompareCount(collection), Is.Zero);
}

[Test]
Expand All @@ -121,7 +121,7 @@ public void CompareCountDisposesSecondEnumerator()

using var seq = TestingSequence.Of<int>();

Assert.AreEqual(0, collection.CompareCount(seq));
Assert.That(collection.CompareCount(seq), Is.Zero);
}

[Test]
Expand All @@ -135,8 +135,8 @@ public void CompareCountDoesNotIterateUnnecessaryElements()

var seq2 = Enumerable.Range(1, 3);

Assert.AreEqual( 1, seq1.CompareCount(seq2));
Assert.AreEqual(-1, seq2.CompareCount(seq1));
Assert.That(seq1.CompareCount(seq2), Is.EqualTo( 1));
Assert.That(seq2.CompareCount(seq1), Is.EqualTo(-1));
}

enum SequenceKind
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq.Test/ConsumeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void ConsumeReallyConsumes()
var counter = 0;
var sequence = Enumerable.Range(0, 10).Pipe(_ => counter++);
sequence.Consume();
Assert.AreEqual(10, counter);
Assert.That(counter, Is.EqualTo(10));
}
}
}
16 changes: 8 additions & 8 deletions MoreLinq.Test/FallbackIfEmptyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public void FallbackIfEmptyPreservesSourceCollectionIfPossible(SourceKind source
{
var source = new[] { 1 }.ToSourceKind(sourceKind);
// ReSharper disable PossibleMultipleEnumeration
Assert.AreSame(source.FallbackIfEmpty(12), source);
Assert.AreSame(source.FallbackIfEmpty(12, 23), source);
Assert.AreSame(source.FallbackIfEmpty(12, 23, 34), source);
Assert.AreSame(source.FallbackIfEmpty(12, 23, 34, 45), source);
Assert.AreSame(source.FallbackIfEmpty(12, 23, 34, 45, 56), source);
Assert.AreSame(source.FallbackIfEmpty(12, 23, 34, 45, 56, 67), source);
Assert.That(source.FallbackIfEmpty(12), Is.SameAs(source));
Assert.That(source.FallbackIfEmpty(12, 23), Is.SameAs(source));
Assert.That(source.FallbackIfEmpty(12, 23, 34), Is.SameAs(source));
Assert.That(source.FallbackIfEmpty(12, 23, 34, 45), Is.SameAs(source));
Assert.That(source.FallbackIfEmpty(12, 23, 34, 45, 56), Is.SameAs(source));
Assert.That(source.FallbackIfEmpty(12, 23, 34, 45, 56, 67), Is.SameAs(source));
// ReSharper restore PossibleMultipleEnumeration
}

Expand All @@ -57,8 +57,8 @@ public void FallbackIfEmptyPreservesFallbackCollectionIfPossible(SourceKind sour
{
var source = new int[0].ToSourceKind(sourceKind);
var fallback = new[] { 1 };
Assert.AreSame(source.FallbackIfEmpty(fallback), fallback);
Assert.AreSame(source.FallbackIfEmpty(fallback.AsEnumerable()), fallback);
Assert.That(source.FallbackIfEmpty(fallback), Is.SameAs(fallback));
Assert.That(source.FallbackIfEmpty(fallback.AsEnumerable()), Is.SameAs(fallback));
}

[Test]
Expand Down
14 changes: 7 additions & 7 deletions MoreLinq.Test/FullGroupJoinTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void FullGroupJoinsResults(OverloadCase overloadCase)

var result = FullGroupJoin(overloadCase, listA, listB, x => x).ToDictionary(a => a.Key);

Assert.AreEqual(3, result.Keys.Count);
Assert.That(result.Keys.Count, Is.EqualTo(3));

Assert.IsEmpty(result[1].Second);
result[1].First.AssertSequenceEqual(1);
Expand All @@ -69,13 +69,13 @@ public void FullGroupJoinsEmptyLeft(OverloadCase overloadCase)

var result = FullGroupJoin(overloadCase, listA, listB, x => x).ToDictionary(a => a.Key);

Assert.AreEqual(2, result.Keys.Count);
Assert.That(result.Keys.Count, Is.EqualTo(2));

Assert.IsEmpty(result[2].First);
Assert.AreEqual(2, result[2].Second.Single());
Assert.That(result[2].Second.Single(), Is.EqualTo(2));

Assert.IsEmpty(result[3].First);
Assert.AreEqual(3, result[3].Second.Single());
Assert.That(result[3].Second.Single(), Is.EqualTo(3));
}

[TestCase(CustomResult)]
Expand All @@ -87,12 +87,12 @@ public void FullGroupJoinsEmptyRight(OverloadCase overloadCase)

var result = FullGroupJoin(overloadCase, listA, listB, x => x).ToDictionary(a => a.Key);

Assert.AreEqual(2, result.Keys.Count);
Assert.That(result.Keys.Count, Is.EqualTo(2));

Assert.AreEqual(2, result[2].First.Single());
Assert.That(result[2].First.Single(), Is.EqualTo(2));
Assert.IsEmpty(result[2].Second);

Assert.AreEqual(3, result[3].First.Single());
Assert.That(result[3].First.Single(), Is.EqualTo(3));
Assert.IsEmpty(result[3].Second);
}

Expand Down
2 changes: 1 addition & 1 deletion MoreLinq.Test/GroupAdjacentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static void AssertResult<TElement>(SequenceReader<TElement> reader, TElement ele
{
var result = reader.Read();
Assert.That(result, Is.Not.Null);
Assert.AreEqual(element, result);
Assert.That(result, Is.EqualTo(element));
}
}
}
10 changes: 5 additions & 5 deletions MoreLinq.Test/LagTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void TestLagExplicitDefaultValue()
var sequence = Enumerable.Range(1, count);
var result = sequence.Lag(lagBy, lagDefault, (_, lagVal) => lagVal);

Assert.AreEqual(count, result.Count());
Assert.That(result.Count(), Is.EqualTo(count));
Assert.That(result.Take(lagBy), Is.EqualTo(Enumerable.Repeat(lagDefault, lagBy)));
}

Expand All @@ -84,7 +84,7 @@ public void TestLagImplicitDefaultValue()
var sequence = Enumerable.Range(1, count);
var result = sequence.Lag(lagBy, (_, lagVal) => lagVal);

Assert.AreEqual(count, result.Count());
Assert.That(result.Count(), Is.EqualTo(count));
Assert.That(result.Take(lagBy), Is.EqualTo(Enumerable.Repeat(default(int), lagBy)));
}

Expand All @@ -99,7 +99,7 @@ public void TestLagOffsetGreaterThanSequenceLength()
var sequence = Enumerable.Range(1, count);
var result = sequence.Lag(count + 1, (a, _) => a);

Assert.AreEqual(count, result.Count());
Assert.That(result.Count(), Is.EqualTo(count));
Assert.That(result, Is.EqualTo(sequence));
}

Expand All @@ -114,7 +114,7 @@ public void TestLagPassesCorrectLagValueOffsetBy1()
var sequence = Enumerable.Range(1, count);
var result = sequence.Lag(1, (a, b) => new { A = a, B = b });

Assert.AreEqual(count, result.Count());
Assert.That(result.Count(), Is.EqualTo(count));
Assert.IsTrue(result.All(x => x.B == (x.A - 1)));
}

Expand All @@ -129,7 +129,7 @@ public void TestLagPassesCorrectLagValuesOffsetBy2()
var sequence = Enumerable.Range(1, count);
var result = sequence.Lag(2, (a, b) => new { A = a, B = b });

Assert.AreEqual(count, result.Count());
Assert.That(result.Count(), Is.EqualTo(count));
Assert.IsTrue(result.Skip(2).All(x => x.B == (x.A - 2)));
Assert.IsTrue(result.Take(2).All(x => (x.A - x.B) == x.A));
}
Expand Down
10 changes: 5 additions & 5 deletions MoreLinq.Test/LeadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void TestLeadExplicitDefaultValue()
var sequence = Enumerable.Range(1, count);
var result = sequence.Lead(leadBy, leadDefault, (_, leadVal) => leadVal);

Assert.AreEqual(count, result.Count());
Assert.That(result.Count(), Is.EqualTo(count));
Assert.That(result.Skip(count - leadBy), Is.EqualTo(Enumerable.Repeat(leadDefault, leadBy)));
}

Expand All @@ -84,7 +84,7 @@ public void TestLeadImplicitDefaultValue()
var sequence = Enumerable.Range(1, count);
var result = sequence.Lead(leadBy, (_, leadVal) => leadVal);

Assert.AreEqual(count, result.Count());
Assert.That(result.Count(), Is.EqualTo(count));
Assert.That(result.Skip(count - leadBy), Is.EqualTo(Enumerable.Repeat(default(int), leadBy)));
}

Expand All @@ -100,7 +100,7 @@ public void TestLeadOffsetGreaterThanSequenceLength()
var sequence = Enumerable.Range(1, count);
var result = sequence.Lead(count + 1, leadDefault, (val, leadVal) => new { A = val, B = leadVal });

Assert.AreEqual(count, result.Count());
Assert.That(result.Count(), Is.EqualTo(count));
Assert.That(result, Is.EqualTo(sequence.Select(x => new { A = x, B = leadDefault })));
}

Expand All @@ -115,7 +115,7 @@ public void TestLeadPassesCorrectValueOffsetBy1()
var sequence = Enumerable.Range(1, count);
var result = sequence.Lead(1, count + 1, (val, leadVal) => new { A = val, B = leadVal });

Assert.AreEqual(count, result.Count());
Assert.That(result.Count(), Is.EqualTo(count));
Assert.IsTrue(result.All(x => x.B == (x.A + 1)));
}

Expand All @@ -131,7 +131,7 @@ public void TestLeadPassesCorrectValueOffsetBy2()
var sequence = Enumerable.Range(1, count);
var result = sequence.Lead(2, leadDefault, (val, leadVal) => new { A = val, B = leadVal });

Assert.AreEqual(count, result.Count());
Assert.That(result.Count(), Is.EqualTo(count));
Assert.IsTrue(result.Take(count - 2).All(x => x.B == (x.A + 2)));
Assert.IsTrue(result.Skip(count - 2).All(x => x.B == leadDefault && x.A is count or count - 1));
}
Expand Down
12 changes: 6 additions & 6 deletions MoreLinq.Test/MaxByTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public void MaxByIsLazy()
[Test]
public void MaxByReturnsMaxima()
{
Assert.AreEqual(new[] { "hello", "world" },
SampleData.Strings.MaxBy(x => x.Length));
Assert.That(SampleData.Strings.MaxBy(x => x.Length),
Is.EqualTo(new[] { "hello", "world" }));
}

[Test]
public void MaxByNullComparer()
{
Assert.AreEqual(SampleData.Strings.MaxBy(x => x.Length),
SampleData.Strings.MaxBy(x => x.Length, null));
Assert.That(SampleData.Strings.MaxBy(x => x.Length, null),
Is.EqualTo(SampleData.Strings.MaxBy(x => x.Length)));
}

[Test]
Expand All @@ -54,13 +54,13 @@ public void MaxByEmptySequence()
[Test]
public void MaxByWithNaturalComparer()
{
Assert.AreEqual(new[] { "az" }, SampleData.Strings.MaxBy(x => x[1]));
Assert.That(SampleData.Strings.MaxBy(x => x[1]), Is.EqualTo(new[] { "az" }));
}

[Test]
public void MaxByWithComparer()
{
Assert.AreEqual(new[] { "aa" }, SampleData.Strings.MaxBy(x => x[1], Comparable<char>.DescendingOrderComparer));
Assert.That(SampleData.Strings.MaxBy(x => x[1], Comparable<char>.DescendingOrderComparer), Is.EqualTo(new[] { "aa" }));
}

public class First
Expand Down
12 changes: 6 additions & 6 deletions MoreLinq.Test/MinByTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public void MinByIsLazy()
[Test]
public void MinByReturnsMinima()
{
Assert.AreEqual(new[] { "ax", "aa", "ab", "ay", "az" },
SampleData.Strings.MinBy(x => x.Length));
Assert.That(SampleData.Strings.MinBy(x => x.Length),
Is.EqualTo(new[] { "ax", "aa", "ab", "ay", "az" }));
}

[Test]
public void MinByNullComparer()
{
Assert.AreEqual(SampleData.Strings.MinBy(x => x.Length),
SampleData.Strings.MinBy(x => x.Length, null));
Assert.That(SampleData.Strings.MinBy(x => x.Length, null),
Is.EqualTo(SampleData.Strings.MinBy(x => x.Length)));
}

[Test]
Expand All @@ -54,13 +54,13 @@ public void MinByEmptySequence()
[Test]
public void MinByWithNaturalComparer()
{
Assert.AreEqual(new[] { "aa" }, SampleData.Strings.MinBy(x => x[1]));
Assert.That(SampleData.Strings.MinBy(x => x[1]), Is.EqualTo(new[] { "aa" }));
}

[Test]
public void MinByWithComparer()
{
Assert.AreEqual(new[] { "az" }, SampleData.Strings.MinBy(x => x[1], Comparable<char>.DescendingOrderComparer));
Assert.That(SampleData.Strings.MinBy(x => x[1], Comparable<char>.DescendingOrderComparer), Is.EqualTo(new[] { "az" }));
}

public class First
Expand Down
Loading