Skip to content

Commit

Permalink
Merge pull request #1852 from jnyrup/FixNaNTest
Browse files Browse the repository at this point in the history
`A_NaN_is_never_in_range_of_two_doubles` was exercising `float`s
  • Loading branch information
jnyrup committed Mar 16, 2022
2 parents 1c0a20b + 5d92b7f commit 2ea786c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
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

0 comments on commit 2ea786c

Please sign in to comment.