Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Is.Zero // Equivalent to Is.EqualTo(0)
## Modifiers

```csharp
...AsCollection
...IgnoreCase
...IgnoreWhiteSpace // From version 4.2
...AsCollection
...NoClip
...WithSameOffset
...Within(object tolerance)
Expand All @@ -37,8 +37,7 @@ Is.Zero // Equivalent to Is.EqualTo(0)
.Seconds
.Milliseconds
.Ticks
...IgnoreCase
...IgnoreWhiteSpace

...Using(IEqualityComparer comparer)
...Using(IComparer comparer)
...Using<T>(IEqualityComparer<T> comparer)
Expand Down Expand Up @@ -118,6 +117,8 @@ to indicate the mismatched location in both _expected_ and _actual_ values:

The `IgnoreWhiteSpace` can also be specified when comparing collections of strings.

The characters ignored are the same as for the C# `Char.IsWhiteSpace`.

## Comparing DateTimes and TimeSpans

**DateTimes** and **TimeSpans** may be compared either with or without a tolerance. A tolerance is specified using
Expand All @@ -136,7 +137,7 @@ Assert.That(later, Is.EqualTo(now).Within(TimeSpan.FromHours(3.0));
Assert.That(later, Is.EqualTo(now).Within(3).Hours);
```

## Comparing Arrays, Collections and IEnumerables
## Comparing Arrays, Collections and IEnumerables with AsCollection

Since version 2.2, NUnit has been able to compare two single-dimensioned arrays. Beginning with version 2.4,
multi-dimensioned arrays, nested arrays (arrays of arrays) and collections may be compared. With version 2.5, any
Expand Down
1 change: 1 addition & 0 deletions docs/snippets/Snippets.NUnit/ConstraintExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
[Test]
public void EqualConstraint_Numerics()
{
Assert.That(2 + 2, Is.EqualTo(4.0));

Check warning on line 15 in docs/snippets/Snippets.NUnit/ConstraintExamples.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

The actual value should not be a constant - perhaps the actual value and the expected value have switched places (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2007.md)
Assert.That(2 + 2 == 4);
Assert.That(2 + 2, Is.Not.EqualTo(5));

Check warning on line 17 in docs/snippets/Snippets.NUnit/ConstraintExamples.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

The actual value should not be a constant - perhaps the actual value and the expected value have switched places (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2007.md)
Assert.That(2 + 2 != 5);
Assert.That(5.0, Is.EqualTo(5));

Check warning on line 19 in docs/snippets/Snippets.NUnit/ConstraintExamples.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

The actual value should not be a constant - perhaps the actual value and the expected value have switched places (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2007.md)
Assert.That(5.5, Is.EqualTo(5).Within(0.5));

Check warning on line 20 in docs/snippets/Snippets.NUnit/ConstraintExamples.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

The actual value should not be a constant - perhaps the actual value and the expected value have switched places (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2007.md)
Assert.That(5.5, Is.EqualTo(5).Within(10).Percent);

Check warning on line 21 in docs/snippets/Snippets.NUnit/ConstraintExamples.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

The actual value should not be a constant - perhaps the actual value and the expected value have switched places (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2007.md)
}
#endregion

Expand All @@ -26,11 +26,11 @@
[Test]
public void EqualConstraint_FloatingPoint()
{
Assert.That(2.1 + 1.2, Is.EqualTo(3.3).Within(.0005));

Check warning on line 29 in docs/snippets/Snippets.NUnit/ConstraintExamples.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

The actual value should not be a constant - perhaps the actual value and the expected value have switched places (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2007.md)
Assert.That(double.PositiveInfinity, Is.EqualTo(double.PositiveInfinity));
Assert.That(double.NegativeInfinity, Is.EqualTo(double.NegativeInfinity));
Assert.That(double.NaN, Is.EqualTo(double.NaN));
Assert.That(20000000000000004.0, Is.EqualTo(20000000000000000.0).Within(1).Ulps);

Check warning on line 33 in docs/snippets/Snippets.NUnit/ConstraintExamples.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

The actual value should not be a constant - perhaps the actual value and the expected value have switched places (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2007.md)
}
#endregion

Expand All @@ -44,6 +44,7 @@
string[] expected = ["Hello", "World"];
string[] actual = ["HELLO", "world"];
Assert.That(actual, Is.EqualTo(expected).IgnoreCase);
Assert.That("Hello my world is \r\n on fire!", Is.EqualTo("Hellomy world \r\n is on fire!").IgnoreWhiteSpace);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun to see our own analyzer warnings on the PR here. :) maybe extract this to a variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to fool the analyzer ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}
#endregion

Expand Down
Loading