Add validity tests to cover edge cases and make validation uniform across languages#750
Open
willbeason wants to merge 2 commits intogoogle:mainfrom
Open
Add validity tests to cover edge cases and make validation uniform across languages#750willbeason wants to merge 2 commits intogoogle:mainfrom
willbeason wants to merge 2 commits intogoogle:mainfrom
Conversation
This improves Go coverage for optimizations I want to be sure are safe.
I added these tests to improve Go coverage for optimizations I want to be sure are safe. In adding these, I found two cases where the libraries of various language handle validation logic inconsistently. In cases of inconsistency, I defaulted to the behavior used by most language in the repository. 1. Automatically expanding requested short code length if odd. Most of the language implementations automatically add 1 to the length of requested codes if the length indicates it is in the pair part of the code. 2. Validate latitude and longitude bounds within validation logic for full codes. Most of the language implementations only check the first two characters for latitude/longitude bounds when within the validation logic for full codes, not when generally checking if codes are valid. This does introduce a strange case where a code is "valid", but is neither a valid short nor a valid long code. As this was the preexisting behavior, I have defaulted to this.
Contributor
Author
|
Opened Issue to document this discrepancy: #751 |
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.
Add validity tests to cover edge cases
I added these tests to improve Go coverage for optimizations I want to be sure are safe. Previously only
Check()was tested, but notCheckShort(),CheckFull()andDecode(), each of which have their own (previously untested) validation logic. In adding these, I found two cases where the libraries of various language handle validation logic inconsistently. In cases of inconsistency, I defaulted to the behavior used by most language in the repository.Automatically expanding requested short code length if odd. Most of the language implementations automatically add 1 to the length of requested codes if the length indicates it is in the pair part of the code.
Validate latitude and longitude bounds within validation logic for full codes. Most of the language implementations only check the first two characters for latitude/longitude bounds when within the validation logic for full codes, not when generally checking if codes are valid. This does introduce a strange case where a code is "valid", but is neither a valid short nor a valid long code. As this was the preexisting behavior, I have defaulted to this.
go: Additionally, I removed the duplicate check for
len(code) == 1inCheckFull(). This path cannot be reached ifCheck()passes. I've added a test to verify this is the case.