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

issue2085_pydecimal_wrong_distribution_for_min_max_values_of_dif_size #2096

Conversation

AlexLitvino
Copy link
Contributor

fixed issue 2085: if min and max values for pydecimal have different signs, faker returned only min_value for negatives

What does this change

  • Changed calculation of left_number when '-' sign is selected and min value is specified
                left_number = str(self.random_int(int(max(max_value or 0, 0)), int(abs(min_value))))
->
                left_number = str(self.random_int(int(abs(min(max_value or 0, 0))), int(abs(min_value))))
  • Added tests to check that all values could be selected from ranges: (-min ... -max), (-min ... +max), (+min ... +max)

What was wrong

When specified equal min and max values with different signs (-min and +max), then for selected '-' sign, left_number always calculated to -min value
left_number = str(self.random_int(int(max(max_value or 0, 0)), int(abs(min_value)))) # min_value is substituted with max_value as they equal by absolute value
->
left_number = str(self.random_int(int(max(max_value or 0, 0)), int(max_value)))
->
left_number = str(self.random_int(int(max_value), int(max_value)) -> max_value

How this fixes it

IF '-' sign is selected, AND min_value is specified, AND max_value is positive, max_value will be calculated as 0.

Fixes #2085

…signs, faker returned only min_value for negatives
Copy link
Collaborator

@fcurella fcurella left a comment

Choose a reason for hiding this comment

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

Thank you!

@fcurella fcurella merged commit e96222c into joke2k:master Sep 19, 2024
28 checks passed
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.

pydecaimal probability issue
2 participants