Skip to content

generate ID Number together with birthday and gender#1316

Merged
kingthorin merged 2 commits intomainfrom
feature/id-number-with-birthday-and-gender
Aug 10, 2024
Merged

generate ID Number together with birthday and gender#1316
kingthorin merged 2 commits intomainfrom
feature/id-number-with-birthday-and-gender

Conversation

@asolntsev
Copy link
Collaborator

this commit adds method IdNumber.valid(IdNumberRequest) which returns a valid combination of ID number, birthday and gender.

Usage:

        PersonIdNumber person = faker.idNumber().valid(new IdNumberRequest(18, 96, ANY));
        PersonIdNumber person = faker.idNumber().valid(new IdNumberRequest(25, 45, FEMALE));

Problem to solve:

In many countries, ID Number contains or depends on birthday and/or gender.
We need to generate a valid person containing a valid combination of ID number, birthday and gender matching each other.

Until now, it was possible to generate them separately, but they didn't always match each other:

        String idNumber = faker.idNumber().valid();  // contains birthday of 80 old man
        LocalDate birthday = faker.timeAndDate().birthday();  // birthday of 16 old woman

this commit adds method IdNumber.valid(IdNumberRequest) which returns a valid combination of ID number, birthday and gender.
@asolntsev asolntsev requested a review from bodiam August 4, 2024 21:30
@codecov
Copy link

codecov bot commented Aug 4, 2024

Codecov Report

Attention: Patch coverage is 88.16568% with 20 lines in your changes missing coverage. Please review.

Project coverage is 91.88%. Comparing base (9cfcfdf) to head (2af34fa).
Report is 6 commits behind head on main.

Files Patch % Lines
...n/java/net/datafaker/idnumbers/PolishIdNumber.java 66.66% 5 Missing ⚠️
...java/net/datafaker/idnumbers/GeorgianIdNumber.java 0.00% 4 Missing ⚠️
src/main/java/net/datafaker/idnumbers/Utils.java 50.00% 3 Missing and 1 partial ⚠️
...in/java/net/datafaker/providers/base/IdNumber.java 62.50% 3 Missing ⚠️
...java/net/datafaker/idnumbers/AmericanIdNumber.java 0.00% 1 Missing ⚠️
...java/net/datafaker/idnumbers/EstonianIdNumber.java 94.11% 0 Missing and 1 partial ⚠️
...va/net/datafaker/idnumbers/PortugueseIdNumber.java 0.00% 1 Missing ⚠️
...a/net/datafaker/idnumbers/SouthKoreanIdNumber.java 91.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1316      +/-   ##
============================================
+ Coverage     91.82%   91.88%   +0.06%     
- Complexity     3096     3145      +49     
============================================
  Files           311      315       +4     
  Lines          6090     6200     +110     
  Branches        631      633       +2     
============================================
+ Hits           5592     5697     +105     
- Misses          342      347       +5     
  Partials        156      156              

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

@bodiam
Copy link
Contributor

bodiam commented Aug 5, 2024

That looks good to me. @kingthorin , any concerns / feedback?

@kingthorin
Copy link
Collaborator

I'll try to review this in the next few hours.

Copy link
Collaborator

@kingthorin kingthorin left a comment

Choose a reason for hiding this comment

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

Only see the one item.

I also predict that we'll have to allow other genders or "prefer not to say" in the future, but I guess that doesn't matter until countries start publishing new specs.

private String sss(BaseProviders faker, boolean female) {
int ordinal = female ? faker.number().numberBetween(500, 1000) : faker.number().numberBetween(0, 500);
private String sss(BaseProviders faker, Gender gender) {
int ordinal = gender == FEMALE ? faker.number().numberBetween(500, 1000) : faker.number().numberBetween(0, 500);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know it was like this before but is 500 really valid for both?

... to avoid potential risk that we will new values to Gender enum, but forget to handle them in such "if"s.
@kingthorin
Copy link
Collaborator

My point was more that it should probably be
0-499
500-1000
Or
0-500
501-1000

If it's supposed to be gender specific how can 500 be valid in both cases?

@asolntsev
Copy link
Collaborator Author

we'll have to allow other genders

Here we are talking only about "genders used for ID numbers". As far as I know, all countries either don't use gender at all, or use MALE/FEMALE option.

If it's supposed to be gender specific how can 500 be valid in both cases?

Yes, this is a valid code because numberBetween function has (minInclusive, maxExclusive) parameters.
In other words,
*numberBetween(500, 1000) means 500 <= X < 1000
*numberBetween(1, 500) means 1 <= X < 500.

@kingthorin
Copy link
Collaborator

Okay sorry, thought it was inclusive

@bodiam
Copy link
Contributor

bodiam commented Aug 10, 2024

@asolntsev want to merge this one?

@asolntsev
Copy link
Collaborator Author

Sure, yes. :)

@kingthorin kingthorin merged commit 28631b8 into main Aug 10, 2024
@kingthorin kingthorin deleted the feature/id-number-with-birthday-and-gender branch August 10, 2024 11:00
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