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

A_NaN_is_never_in_range_of_two_doubles was exercising floats #1852

Merged
merged 1 commit into from Mar 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions Src/FluentAssertions/Numeric/NumericAssertions.cs
Expand Up @@ -189,7 +189,7 @@ public AndConstraint<TAssertions> BeLessThan(T expected, string because = "", pa
{
throw new ArgumentException("A value can never be less than NaN", nameof(expected));
}

Execute.Assertion
.ForCondition(Subject.HasValue && !IsNaN(Subject.Value) && Subject.Value.CompareTo(expected) < 0)
.BecauseOf(because, becauseArgs)
Expand All @@ -216,7 +216,7 @@ public AndConstraint<TAssertions> BeLessThan(T expected, string because = "", pa
{
throw new ArgumentException("A value can never be less than or equal to NaN", nameof(expected));
}

Execute.Assertion
.ForCondition(Subject.HasValue && !IsNaN(Subject.Value) && Subject.Value.CompareTo(expected) <= 0)
.BecauseOf(because, becauseArgs)
Expand Down Expand Up @@ -273,7 +273,7 @@ public AndConstraint<TAssertions> BeLessThan(T expected, string because = "", pa
{
throw new ArgumentException("A value can never be greater than or equal to a NaN", nameof(expected));
}

Execute.Assertion
.ForCondition(Subject.HasValue && Subject.Value.CompareTo(expected) >= 0)
.BecauseOf(because, becauseArgs)
Expand Down Expand Up @@ -309,9 +309,9 @@ public AndConstraint<TAssertions> BeLessThan(T expected, string because = "", pa
{
if (IsNaN(minimumValue) || IsNaN(maximumValue))
{
throw new ArgumentException("A range cannot begin or end with NaN");
throw new ArgumentException("A range cannot begin or end with NaN");
}

Execute.Assertion
.ForCondition(Subject.HasValue && (Subject.Value.CompareTo(minimumValue) >= 0) && (Subject.Value.CompareTo(maximumValue) <= 0))
.BecauseOf(because, becauseArgs)
Expand Down Expand Up @@ -347,7 +347,7 @@ public AndConstraint<TAssertions> BeLessThan(T expected, string because = "", pa
{
throw new ArgumentException("A range cannot begin or end with NaN");
}

Execute.Assertion
.ForCondition(Subject.HasValue && !((Subject.Value.CompareTo(minimumValue) >= 0) && (Subject.Value.CompareTo(maximumValue) <= 0)))
.BecauseOf(because, becauseArgs)
Expand Down Expand Up @@ -480,6 +480,6 @@ public AndConstraint<TAssertions> NotBeOfType(Type unexpectedType, string becaus
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");

private protected virtual bool IsNaN(T value) => false;
private protected virtual bool IsNaN(T value) => false;
}
}
4 changes: 2 additions & 2 deletions Tests/FluentAssertions.Specs/Numeric/NumericAssertionSpecs.cs
Expand Up @@ -678,7 +678,7 @@ public void When_a_value_is_greater_than_greater_value_it_should_throw_with_desc
.Should().Throw<XunitException>()
.WithMessage("Expected value to be greater than 3 because we want to test the failure message, but found 2.");
}

[Fact]
public void NaN_is_never_greater_than_another_float()
{
Expand Down Expand Up @@ -1198,7 +1198,7 @@ public void A_float_can_never_be_in_a_range_containing_NaN(float minimumValue, f
public void A_NaN_is_never_in_range_of_two_doubles()
{
// Arrange
float value = float.NaN;
double value = double.NaN;

// Act
Action act = () => value.Should().BeInRange(4, 5);
Expand Down