Skip to content

Conversation

@asolntsev
Copy link
Collaborator

@asolntsev asolntsev commented May 27, 2024

I realized that PhoneNumberTest almost didn't test anything: it did 10 iterations, but checked that error count is < 25. :)

Now phone numbers are

  • fully correct for et, bg, mk, md, al, ru
  • partially correct for most countries (77% errors tolerance)
  • other countries are marked as FIXME.

@asolntsev asolntsev self-assigned this May 27, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.10%. Comparing base (b37c566) to head (039d54e).
Report is 124 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1225      +/-   ##
============================================
- Coverage     92.35%   92.10%   -0.25%     
- Complexity     2821     3000     +179     
============================================
  Files           292      306      +14     
  Lines          5609     5906     +297     
  Branches        599      628      +29     
============================================
+ Hits           5180     5440     +260     
- Misses          275      306      +31     
- Partials        154      160       +6     

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

I realized that PhoneNumberTest almost didn't test anything: it did 10 iterations, but checked that error count is < 25. :)

Now phone numbers are
* fully correct for et, bg, mk, md, al, ru
* partially correct for most countries (77% errors tolerance)
* other countries are marked as FIXME.
Comment on lines +41 to +42
assertThat(phoneNumber.cellPhone()).matches("(044 )?\\(?\\d+\\)?([- .]\\d+){1,3}");
assertThat(phoneNumber.phoneNumber()).matches("\\(?\\d+\\)?([- .]\\d+){1,3}");
Copy link
Collaborator

Choose a reason for hiding this comment

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

The groupings may as well be non-capturing where possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kingthorin I agree, but now I feel out of resources to refactor these old regexp as well. :(

Copy link
Collaborator

Choose a reason for hiding this comment

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

No problem

}

private static Arguments args(Locale locale, String phoneNumberRegion) {
return args(locale, phoneNumberRegion, (int) (COUNT * 0.77));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thought you said 66?

Copy link
Collaborator

@snuyanzin snuyanzin May 28, 2024

Choose a reason for hiding this comment

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

may be also extract into a var to be able to change everything at one place in case of need?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thought you said 66?

Yes, initially I put 66%, but later had to increase this number to 77% because of flaky tests failed on CI. :)

Copy link
Collaborator Author

@asolntsev asolntsev May 28, 2024

Choose a reason for hiding this comment

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

extract into a var

Yes, I've extracted 77% to a constant.

Comment on lines +131 to +132
private static Arguments args(Locale locale, String phoneNumberRegion, int allowedErrorsCount) {
return Arguments.of(locale, phoneNumberRegion, allowedErrorsCount);
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we just import static for Arguments and then it could be shorter like

of(locale, phoneNumberRegion, allowedErrorsCount);

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's shorter, but is it really readable?
When I read just "of(xxx)", how can I understand what this "of" means"? Of what?

Compared to that, Arguments.of is more readable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

 I guess it depends on the context
if we are talking about of in general then I would agree it is questionable, however here we are in test class, in arguments provider method, with this knowledge it is more readable then from my point of view

Copy link
Collaborator

Choose a reason for hiding this comment

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

anyway i'm not going to stop merging just because of this
I expressed my concerns and leave the final decision up to you

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a huge fan of static imports (AssertJ for example), but in this case, importing "of" doesn't really add to readability, so I'd lean towards keeping the classname there

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I'm too late it seems :)

if (log.isLoggable(FINE)) {
log.fine("Invalid phone: %s".formatted(phoneNumber));
}
errorCount++;
Copy link
Collaborator

@snuyanzin snuyanzin May 28, 2024

Choose a reason for hiding this comment

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

Suggested change
errorCount++;
errorCount++;
if (allowedErrorsCount > errorCount) {
break;
}

I guess there is no need to iterate if we already exceed the limit

+ may be similar approach when a number of rest iterations is less than amount of error we still could make and pass the tests... however in this case there will be less log output 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I've added "break" at these places.
Though, this code is temporary anyway. We need to configure phone numbers to achieve 0 error tolerance. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I tried that some time ago, to get close to zero tolerance, but while I managed for some countries, it was non trivial to get them all in shape. Happy if you give it a shot though

@asolntsev asolntsev merged commit efc9270 into datafaker-net:main May 28, 2024
@asolntsev asolntsev deleted the fix/phone-numbers branch May 28, 2024 10:12
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.

5 participants