#1593 fix Singapore ID number generation#1594
Conversation
`SingaporeIdNumber.CODE` array has length 8 but is used to compute pair-wise weighted sum with random digits of length 7. This commit removes the first element (0). I've tested results with online NRIC validator https://nric.biz/
PR Summary
|
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #1594 +/- ##
============================================
+ Coverage 92.32% 92.43% +0.10%
- Complexity 3354 3358 +4
============================================
Files 331 331
Lines 6620 6619 -1
Branches 655 655
============================================
+ Hits 6112 6118 +6
+ Misses 348 345 -3
+ Partials 160 156 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the Singapore ID number generation where the SingaporeIdNumber.CODE array had an incorrect length that caused invalid NRIC numbers to be generated. The fix ensures that generated Singapore ID numbers pass validation.
Key changes:
- Corrected the
CODEarray by removing the first element to match the expected 7-digit format - Added a new
randomDigits(int length)method to theNumberclass for generating arrays of random digits - Replaced the local
randomDigits()method with the new generic implementation
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/main/java/net/datafaker/idnumbers/SingaporeIdNumber.java |
Fixed CODE array length and replaced local randomDigits method with generic implementation |
src/main/java/net/datafaker/providers/base/Number.java |
Added new randomDigits method to generate arrays of random digits |
src/test/java/net/datafaker/providers/base/NumberTest.java |
Added parameterized test for the new randomDigits method |
Comments suppressed due to low confidence (1)
src/test/java/net/datafaker/providers/base/NumberTest.java:46
- The test should include edge cases such as negative values to ensure the method handles invalid inputs appropriately.
@ValueSource(ints = {0, 1, 2, 3, 4, 8, 16, 25, 36})
It seems that
faker.idNumber().singaporeanFin()generated an invalid NRIC (Singapore id number).Implementation details:
SingaporeIdNumber.CODEarray has length 8 but is used to compute pair-wise weighted sum with random digits of length 7. This commit removes the first element (0).Examples:
I've tested results with online NRIC validator https://nric.biz/
Before the fix applied, we generated invalid NRICs:
G2315872X
G8075162M
G2597018R
G1313234T
G6608713U
G4203779P
G0702189P
G5571430U
G9666778Q
G9738269Q
After fix applied, we generate valid NRICs:
G4961953M
G3182038W
G3812929K
G4053384U
G7061899R
G3675833W
G2142968L
G5946754P
G5916294U
G8598112P
Fixes #1593