Skip to content

Conversation

@arocheleau
Copy link
Contributor

@arocheleau arocheleau commented Mar 12, 2024

Add the BeNaN and NotBeNaN extension methods to NumericAssertionsExtensions.

float value = float.NaN;

value.Should().BeNaN();
value.Should().NotBeNaN();

This fixes #2579.

IMPORTANT

  • If the PR touches the public API, the changes have been approved in a separate issue with the "api-approved" label.
  • The code complies with the Coding Guidelines for C#.
  • The changes are covered by unit tests which follow the Arrange-Act-Assert syntax and the naming conventions such as is used in these tests.
  • If the PR adds a feature or fixes a bug, please update the release notes with a functional description that explains what the change means to consumers of this library, which are published on the website.
  • If the PR changes the public API the changes needs to be included by running AcceptApiChanges.ps1 or AcceptApiChanges.sh.
  • If the PR affects the documentation, please include your changes in this pull request so the documentation will appear on the website.
    • Please also run ./build.sh --target spellcheck or .\build.ps1 --target spellcheck before pushing and check the good outcome

@github-actions
Copy link

github-actions bot commented Mar 12, 2024

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@coveralls
Copy link

coveralls commented Mar 12, 2024

Pull Request Test Coverage Report for Build 8344341172

Details

  • 50 of 50 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 97.555%

Totals Coverage Status
Change from base Build 8329963322: 0.02%
Covered Lines: 11994
Relevant Lines: 12178

💛 - Coveralls

Comment on lines 17 to 21
// Act
Action act = () => actual.Should().BeNaN();

// Assert
act.Should().NotThrow();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Act
Action act = () => actual.Should().BeNaN();
// Assert
act.Should().NotThrow();
// Act / Assert
actual.Should().BeNaN();

We now combine assertions that are not supposed to throw into one.

(And following)

Copy link
Member

@jnyrup jnyrup left a comment

Choose a reason for hiding this comment

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

Looks good 👍
I only have a few minor comments

@arocheleau arocheleau marked this pull request as ready for review March 14, 2024 12:57
/// <summary>
/// Asserts that the float value is NaN.
/// </summary>
/// <param name="parent">The <see cref="NumericAssertions{T}"/> object that is being extended.</param>
Copy link
Member

Choose a reason for hiding this comment

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

🌱 I generally don't document these since they are not relevant for users.

#region BeNaN

/// <summary>
/// Asserts that the float value is NaN.
Copy link
Member

Choose a reason for hiding this comment

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

🤔 I prefer to keep this more functional, e.g. like Asserts that a number is seen as not-a-number.

return new AndConstraint<NullableNumericAssertions<double>>(parent);
}

private static void FailIfValueIsNaN(bool valueIsNaN,
Copy link
Member

Choose a reason for hiding this comment

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

🤔 I'm not a big fan of applying DRY like that. In most cases, duplicating the code makes the implementation much more readable.

@arocheleau arocheleau force-pushed the feature/2579/add-be-nan branch from 4bfd607 to 8da273a Compare March 18, 2024 18:45
Copy link
Member

@dennisdoomen dennisdoomen left a comment

Choose a reason for hiding this comment

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

It would be nice to update the numerictypes.md with the two new methods.

@arocheleau
Copy link
Contributor Author

I did add them to the numerictypes.md earlier, but I guess I missunderstood your comment saying "🌱 I generally don't document these since they are not relevant for users.".

@ITaluone
Copy link
Contributor

ITaluone commented Mar 19, 2024

I did add them to the numerictypes.md earlier, but I guess I missunderstood your comment saying "🌱 I generally don't document these since they are not relevant for users.".

The XML summary on the XxxxAssertions extension methods :)

@dennisdoomen
Copy link
Member

I did add them to the numerictypes.md earlier, but I guess I missunderstood your comment saying "🌱 I generally don't document these since they are not relevant for users.".

I meant the this parent parameter ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for asserting NaN values

6 participants