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

Give fractions and decimals min_value and max_value flags #187

Closed
DRMacIver opened this issue Oct 3, 2015 · 10 comments
Closed

Give fractions and decimals min_value and max_value flags #187

DRMacIver opened this issue Oct 3, 2015 · 10 comments
Labels
enhancement it's not broken, but we want it to be better

Comments

@DRMacIver
Copy link
Member

These mirror the other numeric types (integers, floats).

Note that this is a harder problem than it sounds because the way they're currently implemented does not make it straightforward at all.

It should be pretty feasible to do an exact implementation for fractions but will probably require a custom strategy implementation (it could be done with flatmap, but I would rather it weren't).

Decimals should just be able to convert its bounds to floats and fractions respectively, pass those through to the underlying stragies, and then filter the end result to deal with any imprecision.

@DRMacIver DRMacIver added enhancement it's not broken, but we want it to be better help-wanted labels Oct 3, 2015
@waynew
Copy link

waynew commented Oct 8, 2015

I suspect this would really shave a lot of time off of my tests: right now I'm using assume(decimal.is_finite() and 0 < int(decimal) < 50000), and I'm pretty sure that requires a lot more generations than it could have.

@DRMacIver
Copy link
Member Author

Yeah, if you're doing that you're probably discarding a lot of examples before you find good ones.

Note that this is a help-wanted ticket. If you wanted to submit a pull request I'd be very happy to help you write it (see https://hypothesis.readthedocs.org/en/latest/development.html for details of how this works).

@moreati
Copy link
Contributor

moreati commented Dec 16, 2015

I'm having a go at this

@moreati
Copy link
Contributor

moreati commented Dec 17, 2015

I'm afraid I didn't make progress on this, and I've run out of time.

@mulkieran
Copy link
Contributor

I think that there are some subtleties about fractions and how you would want to test w/ them that I have inadvertently explored in https://github.com/mulkieran/justbases. I don't use the fractions strategy much at all in my tests, instead synthesizing fractional values from integers in various ways. Maybe, since this is up for grabs anyway, it might make sense to think of a few other parameters for fractions strategy that might also be important to have. I will try.

@mulkieran
Copy link
Contributor

Stalls on testRoundFraction()...one of the two places where I was casual enough to use the fractions() strategy: https://travis-ci.org/mulkieran/justbases/builds/110134095.

@mulkieran
Copy link
Contributor

Possibly boundng overall size and also size of numerator and denominator would be enough.

@mulkieran
Copy link
Contributor

It turned out for most of my tests that used fractions() strategy it was necessary to call the Fraction.limit_denominator() method to get the tests to pass in a reasonable time. This was due to the fact that these tests used an explicit, precise division, with an algorithmic efficiency bounded only by the size of the denominator. So, if I limit the denominator to 100, then I have to do at most 100 divisions before I have calculated the repeating portion of the result. This is at least a hint of what modifiers the strategy should have.

@mulkieran
Copy link
Contributor

Maybe max_value, min_value, an upper bound on the absolute value of the product of the numerator and the denominator OR an upper bound on the absolute value of both numerator and denonimator would be adequate.

@Zac-HD
Copy link
Member

Zac-HD commented Apr 14, 2017

Closed by #327

@Zac-HD Zac-HD closed this as completed Apr 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement it's not broken, but we want it to be better
Projects
None yet
Development

No branches or pull requests

5 participants