Git Product home page Git Product logo

Comments (4)

luke-biel avatar luke-biel commented on June 24, 2024

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()
}

from test-case.

leonskidev avatar leonskidev commented on June 24, 2024

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.

from test-case.

luke-biel avatar luke-biel commented on June 24, 2024

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.

from test-case.

leonskidev avatar leonskidev commented on June 24, 2024

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

from test-case.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.