-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: respect both mulitple_of and minimum/maximum constraints
Previously, `generate_constrained_number()` would potentially generate invalid numbers when `mulitple_of` is not None and exactly one of either `minimum` or `maximum` is not None, since it would just return `mulitple_of` without respecting the upper or lower bound. This significantly changes the implementation of `generate_constrained_number()` in an attempt to handle this case. We now first check for the presence of `mulitple_of`, and if it is None, then we return early by delegating to the `method` parameter. Otherwise, we first generate a random number with `method`, and then we attempt to find the nearest number that is a proper multiple of `mulitple_of`. Most of the newly added complexity of the function is meant to handle floating-point or Decimal precision issues, and in worst-case scenarios, it may still not be capable of finding a legal value.
- Loading branch information
1 parent
c4e3d91
commit a65482d
Showing
3 changed files
with
128 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters