Feat/rg module#6
Open
Catskhi wants to merge 2 commits intofullzer4:mainfrom
Open
Conversation
- Implemented RG parsing, validation, formatting, and generation in core and wasm bindings. - Added support for RG check digit computation and symbol removal. - Created tests for RG functionality, including strict and lenient validation cases. - Updated parity generation tool to include RG cases.
fullzer4
requested changes
May 4, 2026
| const SP_BODY_LEN: u8 = 9; | ||
| const SP_FORMATTED_LEN: u8 = 12; | ||
| const SP_BASE_LEN: usize = 8; | ||
| const SP_WEIGHTS: [u32; SP_BASE_LEN] = [2, 3, 4, 5, 6, 7, 8, 9]; |
Owner
There was a problem hiding this comment.
Corrigir este bug saca pai:
O SP_WEIGHTS ta [2, 3, 4, 5, 6, 7, 8, 9] com sum % 11, mas o correto e [9, 8, 7, 6, 5, 4, 3, 2]. Os testes passam porque geram e validam com o mesmo peso errado, mas RGs reais de SP nao batem
Script que valida isto:
WEIGHTS_PR = [2, 3, 4, 5, 6, 7, 8, 9]
WEIGHTS_FIX = [9, 8, 7, 6, 5, 4, 3, 2]
rgs = [
([2,9,4,6,5,3,2,7], 2), # fonte: bosontreinamentos.com.br
([3,9,4,0,6,7,1,4], 9), # fonte: dev.to/shadowlik
]
for digits, dv in rgs:
s = "".join(map(str, digits))
got_pr = sum(d*w for d,w in zip(digits, WEIGHTS_PR)) % 11
got_fix = sum(d*w for d,w in zip(digits, WEIGHTS_FIX)) % 11
print(f"RG {s}-{dv} PR=[2..9]→{got_pr} {'✗' if got_pr!=dv else '✓'} fix=[9..2]→{got_fix} {'✓' if got_fix==dv else '✗'}")Output:
RG 29465327-2 PR=[2..9]→9 ✗ fix=[9..2]→2 ✓
RG 39406714-9 PR=[2..9]→2 ✗ fix=[9..2]→9 ✓
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.