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

Testing for NaN #73

Closed
leonskidev opened this issue Dec 11, 2021 · 4 comments
Closed

Testing for NaN #73

leonskidev opened this issue Dec 11, 2021 · 4 comments

Comments

@leonskidev
Copy link

leonskidev commented Dec 11, 2021

Thanks for the awesome crate!

I was wondering if there was any way to go about testing NaN value equality? I've tried a few ideas to no success (unless I went about them wrong), such as using the hamcrest2 support.

If this isn't possible at the moment then I already have a workaround using regular tests, but maybe it could be supported somehow in the future.

@luke-biel
Copy link
Collaborator

luke-biel commented Dec 11, 2021

Without code snippet it's hard for me to help you with your exact problem, but I'm assuming you have something like this:

#[test_case(input => 1.0)]
#[test_case(input2 => NaN)]
fn test(input: X) -> f64 {
	stuff...
}

NaN == Nan resolves to false by design, it's not even a rust thing. I don't see an easy way to do this in single function, not with current syntax of test_case. You'd have to be able to provide custom assertion, which would for this NaN case validate it via !value.is_nan(). Custom assertions aren't supported within the lib though.
What I would try to do is to separate this into two functions, one that tests "correct" outcomes and one that checks for NaN and returns a boolean.

#[test_case(input => 1.0)]
fn test(input: X) -> f64 {
	stuff...
}
#[test_case(input2 => true)]
fn test(input: X) -> bool {
	(stuff that returns NaN...).is_nan()
}

@leonskidev
Copy link
Author

Without code snippet it's hard for me to help you with your exact problem.

Thanks, I knew I forgot to do something when posting the issue. (whoops)

NaN == NaN resolves to false by design, it's not even a rust thing.

Yep, I should have made my understanding of this clearer. (whoops)

I was more so wondering if a feature was in the works for these sorts of tests, or for a possible future idea? If not then it's all good, just couldn't find an issue referring to that was all.

@luke-biel
Copy link
Collaborator

Understood.
Well, there were plans for mentioned custom assertions #31, but we've never came to an agreement on how they should look like, so the idea sits there waiting for a better time.

@leonskidev
Copy link
Author

Ah, coolio. Thanks for the help and information anyway. I look forward to using this crate in more projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants