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

Fix pyfloat out of min/max range #1062

Merged
merged 6 commits into from Dec 3, 2019
Merged

Fix pyfloat out of min/max range #1062

merged 6 commits into from Dec 3, 2019

Conversation

bryan-brancotte
Copy link
Contributor

@bryan-brancotte bryan-brancotte commented Nov 22, 2019

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

  • When the min is lower than 0, we increase it of one (-6 -> -5) as digits are appended later
  • When the max is lower than 0, we increase it of one (-6 -> -5) as the number before the comma is generated up to max - 1

@@ -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
Copy link
Collaborator

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

assert result >= 0.0
assert result <= 1.0
for i in range(20):
for min_value,max_value in [
Copy link
Collaborator

@fcurella fcurella Dec 2, 2019

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 [

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks !

@bryan-brancotte bryan-brancotte changed the title WIP: Fix pyfloat out of min/max range Fix pyfloat out of min/max range Dec 3, 2019
@bryan-brancotte
Copy link
Contributor Author

flake8 ci fixed, thanks to @fcurella . Only remains the dependency issue with python3.5 which I see in other PR:

pkg_resources.DistributionNotFound: The 'python-dateutil>=2.4' distribution was not found and is required by the application

@fcurella
Copy link
Collaborator

fcurella commented Dec 3, 2019

Thank you! ✨

@fcurella fcurella merged commit 16d2e6c into joke2k:master Dec 3, 2019
@bryan-brancotte
Copy link
Contributor Author

you are welcome

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

Successfully merging this pull request may close these issues.

None yet

2 participants