fc.integer() causes non-terminating behaviour when given certain non-integer arguments for min and max
See original GitHub issue🐛 Bug Report
When using fc.integer() with max
and min
parameters, if 0.5 <= (max - min) < 1
, then running through fc.assert(fc.property(...))
does not terminate.
To Reproduce
Steps to reproduce:
Any of the following lines do not terminate:
fc.assert(fc.property(fc.integer({ min: 0, max: 0.5 }), () => true))
fc.assert(fc.property(fc.integer({ min: 0, max: 0.999 }), () => true))
fc.assert(fc.property(fc.integer({ min: 0.5, max: 1.4999 }), () => true))
fc.assert(fc.property(fc.integer({ min: 0.5, max: 1 }), () => true))
All of the following do terminate:
fc.assert(fc.property(fc.integer({ min: 0, max: 0 }), () => true))
fc.assert(fc.property(fc.integer({ min: 1, max: 1 }), () => true))
fc.assert(fc.property(fc.integer({ min: 0, max: 0.4999 }), () => true))
fc.assert(fc.property(fc.integer({ min: 0, max: 1 }), () => true))
fc.assert(fc.property(fc.integer({ min: 0, max: 1.5 }), () => true))
fc.assert(fc.property(fc.integer({ min: 0.5, max: 1.5 }), () => true))
Expected behavior
I expect either:
- the
min
andmax
values behave as if they were rounded (or floored, or even ceiled) to an appropriate integer value, - or an error to be thrown for specifying non-integer parameters.
Your environment
Packages / Softwares | Version(s) |
---|---|
fast-check | 2.17.0 |
node | 14.16.0 |
TypeScript | 4.2.4 |
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Maxima and Minima - R
a logical indicating whether missing values should be removed. Details. max and min return the maximum or minimum of all the values present...
Read more >Mathematics for Computer Science - MIT CS
This text explains how to use mathematical models and methods to analyze prob- lems that arise in computer science. Proofs play a central...
Read more >manual.pdf - REDUCE Computer Algebra System
If all arguments evaluate to numerical values, the maximum or minimum of the ... expressions involving the product of variables raised to non-integer...
Read more >Python's min() and max(): Find Smallest and Largest Values
In this tutorial, you'll learn how to use Python's built-in min() and max() functions to find the smallest and largest values.
Read more >Use of min and max functions in C++ - Stack Overflow
fmin and fmax are specifically for use with floating point numbers (hence the "f"). If you use it for ints, you may suffer...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually no.
Good point! We can clearly go for 2. I was mostly challenging a bit the need but your example makes it clear: it’s easy to fall in such case, so let’s add checks to ensure passed min/max are ok*. *meaning: between min safe and max safe, Number.isInteger
@julianmrodri Not related to this issue. Your issue is linked to the warning:
Visible here: https://github.com/dubzzz/fast-check/blob/main/documentation/AdvancedArbitraries.md#filter-values
In your case you ask the arbitrary for values between
0n
and115792089237316195423570985008687907853269984665640564039457584007913129639936n
but only keep a very very very limited range. In your case filter will always reject the generated values as the chance to fall in your filtering range is barely null (bigUint arbitrary can produce any value with the same proba - more or less true once we stop biasing generated values).