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

Added numberBetween for doubles. #1392

Merged
merged 8 commits into from
Nov 2, 2024
Merged

Added numberBetween for doubles. #1392

merged 8 commits into from
Nov 2, 2024

Conversation

bodiam
Copy link
Contributor

@bodiam bodiam commented Oct 19, 2024

No description provided.

Copy link

what-the-diff bot commented Oct 19, 2024

PR Summary

  • Modification of the 'numberBetween' method
    The method for generating a random number within a given range has been updated. It is now more flexible and easier to modify in the future.

  • Addition of a new 'numberBetween' method
    A new version of the method for generating a random number has been created. This one accommodates decimal numbers between set boundaries, extending usability for calculations requiring more precision.

  • Improving the testing structure
    To secure the efficiency and accuracy of the new method, a special test has been integrated into our regular testing sequence. It safeguards that the generated decimal numbers actually do fall into their prescribed range. This guarantees reliable results for future calculations.

@kingthorin
Copy link
Collaborator

@RepeatedTest(100)
void numberBetweenRepeated() {
assertThat(faker.expression("#{number.number_between '1','10'}")).matches("[1-9]");
}

@bodiam
Copy link
Contributor Author

bodiam commented Oct 26, 2024

numberBetweenRepeated

Interesting. What should we do with this? I think what I'm basically asking is:
"#{number.number_between '1','10'}", should/could that return 1.5?

@kingthorin
Copy link
Collaborator

Yes in this case it could be.

@bodiam
Copy link
Contributor Author

bodiam commented Oct 26, 2024

Yes in this case it could be.

I agree. I'm just not sure if that's going to break anything. Probably not likely, but not sure. Any suggestions on what to do here? Reject the PR, fix the test, something else?

@kingthorin
Copy link
Collaborator

I see two options.

  1. Adjust the regex
  2. Make the double method specific instead of numberBetween maybe doubleBetween.

Comment on lines +68 to +69
public double numberBetween(double min, double max) {
return faker.random().nextDouble(min, max);
Copy link
Collaborator

Choose a reason for hiding this comment

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

it looks like nothing prevents from calling it like

faker.number().numberBetween(123.456, 1.0);

what is expected output of it?
based on name the result should be somewhere between the boudaries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same as what the other methods return.

faker.number().numberBetween(10, 0) 

Also returns a number between 0 and 10.

Copy link
Collaborator

Choose a reason for hiding this comment

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

would be great to have a test for this case as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, I added it.

@bodiam
Copy link
Contributor Author

bodiam commented Nov 1, 2024

@kingthorin

Adjust the regex

I did.

Copy link

codecov bot commented Nov 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.06%. Comparing base (87a3803) to head (59c4c7c).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1392      +/-   ##
============================================
- Coverage     92.26%   92.06%   -0.20%     
+ Complexity     3166     3157       -9     
============================================
  Files           320      320              
  Lines          6177     6178       +1     
  Branches        592      592              
============================================
- Hits           5699     5688      -11     
- Misses          335      344       +9     
- Partials        143      146       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bodiam bodiam merged commit f073184 into main Nov 2, 2024
10 checks passed
@bodiam bodiam deleted the double-between branch November 2, 2024 03:50
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.

3 participants