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
Fix pyfloat out of min/max range #1062
Conversation
Former test did not spot returned value can be out of range
faker/providers/python/__init__.py
Outdated
@@ -60,6 +60,10 @@ def pyfloat(self, left_digits=None, right_digits=None, positive=False, | |||
self.random_int(0, sys.float_info.dig - left_digits)) | |||
sign = '' | |||
if (min_value is not None) or (max_value is not None): | |||
if max_value is not None and max_value < 0: | |||
max_value += 1 # as the random_int will be generated up to max_value - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at least two spaces before the inline comment
tests/test_factory.py
Outdated
assert result >= 0.0 | ||
assert result <= 1.0 | ||
for i in range(20): | ||
for min_value,max_value in [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space: for min_value, max_value in [
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks !
flake8 ci fixed, thanks to @fcurella . Only remains the dependency issue with python3.5 which I see in other PR:
|
Thank you! ✨ |
you are welcome |
Ensure that pyfloat stays within range defined by min max
What does this changes
Add tests, and shift min and max when they are negative
What was wrong
When min was lower than 0, former code generated values between [min-1; max], so did for max
How this fixes it
0
, we increase it of one (-6
->-5
) as digits are appended later0
, we increase it of one (-6
->-5
) as the number before the comma is generated up tomax - 1