Skip to content

Add max code length tests, fix behavior for Python, Rust and C++ #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 29, 2019

Conversation

WilliamDenniss
Copy link
Contributor

Replaces #287, moves tests to data files.

Includes #299 (I will rebase when that is merged).

@WilliamDenniss WilliamDenniss changed the title Implement max code length behavior for Python Add max code length tests, implement max code length behavior for Python Apr 24, 2019
@zongweil
Copy link
Contributor

The C++ library seems to be failing the new tests. If you have time, would you mind looking into it? If not, I can take a look next week.

@WilliamDenniss WilliamDenniss force-pushed the maxlength branch 3 times, most recently from 38f46c7 to 66a4636 Compare April 25, 2019 06:29
@WilliamDenniss WilliamDenniss changed the title Add max code length tests, implement max code length behavior for Python Add max code length tests, fix behavior for Python, Rust and C++ Apr 25, 2019
@WilliamDenniss
Copy link
Contributor Author

Sure thing, I fixed the C++ issue (was returning the original size in the CodeArea object) by moving the truncation a bit earlier.

@WilliamDenniss
Copy link
Contributor Author

@zongweil I believe this is good to go, all implementations are now passing the tests I added to verify the max code length behavior.

@@ -199,7 +199,7 @@ std::string Encode(const LatLng &location) {

CodeArea Decode(const std::string &code) {
// Make a copy that doesn't have the separator and stops at the first padding
// character.
// character, and is constrained to the maximum length.
std::string clean_code(code);
clean_code.erase(
Copy link
Contributor

Choose a reason for hiding this comment

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

The code from lines 203-210 seems to be duplicated in CodeLength(). Can you extract and de-dupe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing! Done.

As documented in issue number 190:
1. If you ask the library to encode a lat/long with more than 15 digits, the library will return a plus code with 15 digits.
2. If you ask the library to decode a plus code with more than 15 digits, the library will only take the first 15 digits into account with the returned code area.
3. Plus codes with more than 15 digits will be treated as valid if all the other validity constraints are satisfied. If the plus code has an invalid character after the 15th digit, it will be treated as invalid.
Limit decoding to first 15 significant digits.
Decode was only processing the first 15 significant digits, but
was returning the length of the entire code.

Refactored a little to move the truncation earlier.
@WilliamDenniss
Copy link
Contributor Author

@zongweil this should be ready now, PTAL :)

@@ -92,6 +92,19 @@ double adjust_latitude(double latitude_degrees, size_t code_length) {
return latitude_degrees - precision / 2;
}

// Remove the separateor and padding characters from the code.
Copy link
Contributor

Choose a reason for hiding this comment

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

separator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@zongweil
Copy link
Contributor

Thanks! One typo, I'll merge it in right after :).

@zongweil zongweil merged commit 8bfbdfb into google:master Apr 29, 2019
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.

2 participants