Skip to content

Added numberBetween for doubles.#1392

Merged
bodiam merged 8 commits intomainfrom
double-between
Nov 2, 2024
Merged

Added numberBetween for doubles.#1392
bodiam merged 8 commits intomainfrom
double-between

Conversation

@bodiam
Copy link
Copy Markdown
Contributor

@bodiam bodiam commented Oct 19, 2024

No description provided.

@what-the-diff
Copy link
Copy Markdown

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
Copy Markdown
Collaborator

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

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

Yes in this case it could be.

@bodiam
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

bodiam commented Nov 1, 2024

@kingthorin

Adjust the regex

I did.

@codecov
Copy link
Copy Markdown

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
@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